/** * Prepare the text fields and save them * * @param int $id * @return bool|int */ public function save($data = '') { if (!empty($data[$this->pkey])) { $this->delete($data[$this->pkey]); } $data['full'] = prepare_text($data['original']); $data['short'] = mb_strcut($data['full'], 0, 250); // @todo: 250 should be in CONFIG return parent::insert($data); }
function connect_content(&$a) { $edit = local_user() && local_user() == $a->data['channel']['channel_id'] ? true : false; $text = get_pconfig($a->data['channel']['channel_id'], 'system', 'selltext'); if ($edit) { $o = replace_macros(get_markup_template('sellpage_edit.tpl'), array('$header' => t('Premium Channel Setup'), '$address' => $a->data['channel']['channel_address'], '$premium' => array('premium', t('Enable premium channel connection restrictions'), $a->data['channel']['channel_pageflags'] & PAGE_PREMIUM ? '1' : '', ''), '$lbl_about' => t('Please enter your restrictions or conditions, such as paypal receipt, usage guidelines, etc.'), '$text' => $text, '$desc' => t('This channel may require additional steps or acknowledgement of the following conditions prior to connecting:'), '$lbl2' => t('Potential connections will then see the following text before proceeding:'), '$desc2' => t('By continuing, I certify that I have complied with any instructions provided on this page.'), '$submit' => t('Submit'))); return $o; } else { if (!$text) { $text = t('(No specific instructions have been provided by the channel owner.)'); } $submit = replace_macros(get_markup_template('sellpage_submit.tpl'), array('$continue' => t('Continue'), '$address' => $a->data['channel']['channel_address'])); $o = replace_macros(get_markup_template('sellpage_view.tpl'), array('$header' => t('Restricted or Premium Channel'), '$desc' => t('This channel may require additional steps or acknowledgement of the following conditions prior to connecting:'), '$text' => prepare_text($text), '$desc2' => t('By continuing, I certify that I have complied with any instructions provided on this page.'), '$submit' => $submit)); $arr = array('channel' => $a->data['channel'], 'observer' => $a->get_observer(), 'sellpage' => $o, 'submit' => $submit); call_hooks('connect_premium', $arr); $o = $arr['sellpage']; } return $o; }
function prepare_body($item, $attach = false) { $a = get_app(); call_hooks('prepare_body_init', $item); //$cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body'])); $cachefile = get_cachefile($item["guid"] . "-" . hash("md5", $item['body'])); if ($cachefile != '') { if (file_exists($cachefile)) { $stamp1 = microtime(true); $s = file_get_contents($cachefile); $a->save_timestamp($stamp1, "file"); } else { redir_private_images($a, $item); $s = prepare_text($item['body']); $stamp1 = microtime(true); file_put_contents($cachefile, $s); $a->save_timestamp($stamp1, "file"); logger('prepare_body: put item ' . $item["id"] . ' into cachefile ' . $cachefile); } } else { redir_private_images($a, $item); $s = prepare_text($item['body']); } $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body', $prep_arr); $s = $prep_arr['html']; if (!$attach) { // Replace the blockquotes with quotes that are used in mails $mailquote = '<blockquote type="cite" class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">'; $s = str_replace(array('<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'), array($mailquote, $mailquote, $mailquote), $s); return $s; } $arr = explode('[/attach],', $item['attach']); if (count($arr)) { $s .= '<div class="body-attach">'; foreach ($arr as $r) { $matches = false; $icon = ''; $cnt = preg_match_all('|\\[attach\\]href=\\"(.*?)\\" length=\\"(.*?)\\" type=\\"(.*?)\\" title=\\"(.*?)\\"|', $r, $matches, PREG_SET_ORDER); if ($cnt) { foreach ($matches as $mtch) { $filetype = strtolower(substr($mtch[3], 0, strpos($mtch[3], '/'))); if ($filetype) { $filesubtype = strtolower(substr($mtch[3], strpos($mtch[3], '/') + 1)); $filesubtype = str_replace('.', '-', $filesubtype); } else { $filetype = 'unkn'; $filesubtype = 'unkn'; } $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>'; /*$icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/'))); switch($icontype) { case 'video': case 'audio': case 'image': case 'text': $icon = '<div class="attachtype icon s22 type-' . $icontype . '"></div>'; break; default: $icon = '<div class="attachtype icon s22 type-unkn"></div>'; break; }*/ $title = strlen(trim($mtch[4])) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1]); $title .= ' ' . $mtch[2] . ' ' . t('bytes'); if (local_user() == $item['uid'] && $item['contact-id'] != $a->contact['id'] && $item['network'] == NETWORK_DFRN) { $the_url = $a->get_baseurl() . '/redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1]; } else { $the_url = $mtch[1]; } $s .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="external-link" >' . $icon . '</a>'; } } } $s .= '<div class="clear"></div></div>'; } // Look for spoiler $spoilersearch = '<blockquote class="spoiler">'; // Remove line breaks before the spoiler while (strpos($s, "\n" . $spoilersearch) !== false) { $s = str_replace("\n" . $spoilersearch, $spoilersearch, $s); } while (strpos($s, "<br />" . $spoilersearch) !== false) { $s = str_replace("<br />" . $spoilersearch, $spoilersearch, $s); } while (strpos($s, $spoilersearch) !== false) { $pos = strpos($s, $spoilersearch); $rnd = random_string(8); $spoilerreplace = '<br /> <span id="spoiler-wrap-' . $rnd . '" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'spoiler-' . $rnd . '\');">' . sprintf(t('Click to open/close')) . '</span>' . '<blockquote class="spoiler" id="spoiler-' . $rnd . '" style="display: none;">'; $s = substr($s, 0, $pos) . $spoilerreplace . substr($s, $pos + strlen($spoilersearch)); } // Look for quote with author $authorsearch = '<blockquote class="author">'; while (strpos($s, $authorsearch) !== false) { $pos = strpos($s, $authorsearch); $rnd = random_string(8); $authorreplace = '<br /> <span id="author-wrap-' . $rnd . '" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'author-' . $rnd . '\');">' . sprintf(t('Click to open/close')) . '</span>' . '<blockquote class="author" id="author-' . $rnd . '" style="display: block;">'; $s = substr($s, 0, $pos) . $authorreplace . substr($s, $pos + strlen($authorsearch)); } $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body_final', $prep_arr); return $prep_arr['html']; }
function api_format_items($r, $user_info) { //logger('api_format_items: ' . print_r($r,true)); //logger('api_format_items: ' . print_r($user_info,true)); $a = get_app(); $ret = array(); if (!$r) { return $ret; } foreach ($r as $item) { localize_item($item); $status_user = $item['author_xchan'] == $user_info['guid'] ? $user_info : api_item_get_user($a, $item); if (array_key_exists('status', $status_user)) { unset($status_user['status']); } if ($item['parent'] != $item['id']) { $r = q("select id from item where parent= %d and id < %d order by id desc limit 1", intval($item['parent']), intval($item['id'])); if ($r) { $in_reply_to_status_id = $r[0]['id']; } else { $in_reply_to_status_id = $item['parent']; } xchan_query($r, true); $in_reply_to_screen_name = $r[0]['author']['xchan_name']; $in_reply_to_user_id = $r[0]['author']['abook_id']; } else { $in_reply_to_screen_name = ''; $in_reply_to_user_id = 0; $in_reply_to_status_id = 0; } unobscure($item); // Workaround for ostatus messages where the title is identically to the body $statusbody = trim(html2plain(prepare_text($item['body'], $item['mimetype']), 0)); $statustitle = trim($item['title']); if ($statustitle != '' and strpos($statusbody, $statustitle) !== false) { $statustext = trim($statusbody); } else { $statustext = trim($statustitle . "\n\n" . $statusbody); } $status = array('text' => $statustext, 'truncated' => False, 'created_at' => api_date($item['created']), 'in_reply_to_status_id' => $in_reply_to_status_id, 'source' => $item['app'] ? $item['app'] : 'web', 'id' => intval($item['id']), 'in_reply_to_user_id' => $in_reply_to_user_id, 'in_reply_to_screen_name' => $in_reply_to_screen_name, 'geo' => '', 'favorited' => intval($item['item_starred']) ? true : false, 'user' => $status_user, 'statusnet_html' => trim(prepare_text($item['body'], $item['mimetype'])), 'statusnet_conversation_id' => $item['parent']); // Seesmic doesn't like the following content if ($_SERVER['HTTP_USER_AGENT'] != 'Seesmic') { $status2 = array('updated' => api_date($item['edited']), 'published' => api_date($item['created']), 'message_id' => $item['mid'], 'url' => $item['plink'], 'coordinates' => $item['coord'], 'place' => $item['location'], 'contributors' => '', 'annotations' => '', 'entities' => '', 'objecttype' => $item['obj_type'] ? $item['obj_type'] : ACTIVITY_OBJ_NOTE, 'verb' => $item['verb'] ? $item['verb'] : ACTIVITY_POST, 'self' => $a->get_baseurl() . "/api/statuses/show/" . $item['id'] . "." . $type, 'edit' => $a->get_baseurl() . "/api/statuses/show/" . $item['id'] . "." . $type); $status = array_merge($status, $status2); } $ret[] = $status; } return $ret; }
function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) { if (!$item['parent']) { return; } if ($item['deleted']) { return '<at:deleted-entry ref="' . xmlify($item['mid']) . '" when="' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '" />' . "\r\n"; } if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) { $body = fix_private_photos($item['body'], $owner['uid'], $item, $cid); } else { $body = $item['body']; } $o = "\r\n\r\n<entry>\r\n"; if (is_array($author)) { $o .= atom_author('author', $author['xchan_name'], $author['xchan_url'], 80, 80, $author['xchan_photo_mimetype'], $author['xchan_photo_m']); } else { $o .= atom_author('author', $item['author']['xchan_name'], $item['author']['xchan_url'], 80, 80, $item['author']['xchan_photo_mimetype'], $item['author']['xchan_photo_m']); } $o .= atom_author('zot:owner', $item['owner']['xchan_name'], $item['owner']['xchan_url'], 80, 80, $item['owner']['xchan_photo_mimetype'], $item['owner']['xchan_photo_m']); if ($item['parent'] != $item['id'] || $item['parent_mid'] !== $item['mid'] || $item['thr_parent'] !== '' && $item['thr_parent'] !== $item['mid']) { $parent_item = $item['thr_parent'] ? $item['thr_parent'] : $item['parent_mid']; $o .= '<thr:in-reply-to ref="' . xmlify($parent_item) . '" type="text/html" href="' . xmlify($item['plink']) . '" />' . "\r\n"; } $o .= '<id>' . xmlify($item['mid']) . '</id>' . "\r\n"; $o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n"; $o .= '<published>' . xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', ATOM_TIME)) . '</published>' . "\r\n"; $o .= '<updated>' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '</updated>' . "\r\n"; $o .= '<content type="' . $type . '" >' . xmlify(prepare_text($body, $item['mimetype'])) . '</content>' . "\r\n"; $o .= '<link rel="alternate" type="text/html" href="' . xmlify($item['plink']) . '" />' . "\r\n"; if ($item['location']) { $o .= '<zot:location>' . xmlify($item['location']) . '</zot:location>' . "\r\n"; $o .= '<poco:address><poco:formatted>' . xmlify($item['location']) . '</poco:formatted></poco:address>' . "\r\n"; } if ($item['coord']) { $o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n"; } if ($item['item_private'] || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) { $o .= '<zot:private>' . ($item['item_private'] ? $item['item_private'] : 1) . '</zot:private>' . "\r\n"; } if ($item['app']) { $o .= '<statusnet:notice_info local_id="' . $item['id'] . '" source="' . xmlify($item['app']) . '" ></statusnet:notice_info>' . "\r\n"; } $verb = construct_verb($item); $o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n"; $actobj = construct_activity_object($item); if (strlen($actobj)) { $o .= $actobj; } $actarg = construct_activity_target($item); if (strlen($actarg)) { $o .= $actarg; } // FIXME // $tags = item_getfeedtags($item); // if(count($tags)) { // foreach($tags as $t) { // $o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n"; // } // } // FIXME // $o .= item_getfeedattach($item); // $mentioned = get_mentions($item,$tags); // if($mentioned) // $o .= $mentioned; call_hooks('atom_entry', $o); $o .= '</entry>' . "\r\n"; return $o; }
/** * Add new comment to topic */ public function comment() { $this->load->model('comment'); $comment['post_id'] = param('post_id'); if (empty($comment['post_id'])) { set_flash_error('Ошибка в параметрах комментария'); redirect(); } $post = $this->post->find($comment['post_id'], 1); if (empty($post)) { set_flash_error('Такого топика не существует'); redirect(); } $comment['parent_id'] = param('parent_id'); $comment['text'] = prepare_text(param('text', TRUE, FALSE)); if (empty($comment['text'])) { set_flash_error('Вы не написали свой комментарий к топику'); redirect(post_link($post)); } $comment['user_id'] = $this->current_user['id']; $comment['added_at'] = now2mysql(); $id = $this->comment->save($comment); if ($id) { set_flash_ok('Спасибо за ваш комментарий'); } else { set_flash_error('Извините, но произошла ошибка и ваш комментарий сохранить не удалось'); } redirect(post_link($post) . '#com' . $id); }
function prepare_body(&$item, $attach = false) { require_once 'include/identity.php'; // if($item['html']) { // $s = bb_observer($item['html']); // } // else { call_hooks('prepare_body_init', $item); // unobscure($item); $s = prepare_text($item['body'], $item['mimetype'], false); // } $photo = ''; $is_photo = $item['obj_type'] === ACTIVITY_OBJ_PHOTO ? true : false; if ($is_photo) { $object = json_decode($item['object'], true); // if original photo width is <= 640px prepend it to item body if ($object['link'][0]['width'] && $object['link'][0]['width'] <= 640) { $s = '<div class="inline-photo-item-wrapper"><a href="' . zid(rawurldecode($object['id'])) . '" target="_newwin"><img class="inline-photo-item" style="max-width:' . $object['link'][0]['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($object['link'][0]['href'])) . '"></a></div>' . $s; } // if original photo width is > 640px make it a cover photo if ($object['link'][0]['width'] && $object['link'][0]['width'] > 640) { $scale = $object['link'][1]['width'] == 1024 || $object['link'][1]['height'] == 1024 ? 1 : 0; $photo = '<a href="' . zid(rawurldecode($object['id'])) . '" target="_newwin"><img style="max-width:' . $object['link'][$scale]['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($object['link'][$scale]['href'])) . '"></a>'; } } $prep_arr = array('item' => $item, 'html' => $s, 'photo' => $photo); call_hooks('prepare_body', $prep_arr); $s = $prep_arr['html']; $photo = $prep_arr['photo']; // q("update item set html = '%s' where id = %d", // dbesc($s), // intval($item['id']) // ); if (!$attach) { return $s; } if (strpos($s, '<div class="map">') !== false && $item['coord']) { $x = generate_map(trim($item['coord'])); if ($x) { $s = preg_replace('/\\<div class\\=\\"map\\"\\>/', '$0' . $x, $s); } } $attachments = theme_attachments($item); $writeable = get_observer_hash() == $item['owner_xchan'] ? true : false; $tags = format_hashtags($item); if ($item['resource_type']) { $mentions = format_mentions($item); } $categories = format_categories($item, $writeable); if (local_channel() == $item['uid']) { $filer = format_filer($item); } $s = sslify($s); // Look for spoiler $spoilersearch = '<blockquote class="spoiler">'; // Remove line breaks before the spoiler while (strpos($s, "\n" . $spoilersearch) !== false) { $s = str_replace("\n" . $spoilersearch, $spoilersearch, $s); } while (strpos($s, "<br />" . $spoilersearch) !== false) { $s = str_replace("<br />" . $spoilersearch, $spoilersearch, $s); } while (strpos($s, $spoilersearch) !== false) { $pos = strpos($s, $spoilersearch); $rnd = random_string(8); $spoilerreplace = '<br /> <span id="spoiler-wrap-' . $rnd . '" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'spoiler-' . $rnd . '\');">' . sprintf(t('Click to open/close')) . '</span>' . '<blockquote class="spoiler" id="spoiler-' . $rnd . '" style="display: none;">'; $s = substr($s, 0, $pos) . $spoilerreplace . substr($s, $pos + strlen($spoilersearch)); } // Look for quote with author $authorsearch = '<blockquote class="author">'; while (strpos($s, $authorsearch) !== false) { $pos = strpos($s, $authorsearch); $rnd = random_string(8); $authorreplace = '<br /> <span id="author-wrap-' . $rnd . '" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'author-' . $rnd . '\');">' . sprintf(t('Click to open/close')) . '</span>' . '<blockquote class="author" id="author-' . $rnd . '" style="display: block;">'; $s = substr($s, 0, $pos) . $authorreplace . substr($s, $pos + strlen($authorsearch)); } $prep_arr = array('item' => $item, 'photo' => $photo, 'html' => $s, 'categories' => $categories, 'folders' => $filer, 'tags' => $tags, 'mentions' => $mentions, 'attachments' => $attachments); call_hooks('prepare_body_final', $prep_arr); unset($prep_arr['item']); return $prep_arr; }
function store_doc_file($s) { if (is_dir($s)) { return; } $item = array(); $sys = get_sys_channel(); $item['aid'] = 0; $item['uid'] = $sys['channel_id']; if (strpos($s, '.md')) { $mimetype = 'text/markdown'; } elseif (strpos($s, '.html')) { $mimetype = 'text/html'; } else { $mimetype = 'text/bbcode'; } require_once 'include/html2plain.php'; $item['body'] = html2plain(prepare_text(file_get_contents($s), $mimetype, true)); $item['mimetype'] = 'text/plain'; $item['plink'] = z_root() . '/' . str_replace('doc', 'help', $s); $item['owner_xchan'] = $item['author_xchan'] = $sys['channel_hash']; $item['item_type'] = ITEM_TYPE_DOC; $r = q("select item.* from item left join iconfig on item.id = iconfig.iid \n\t\twhere iconfig.cat = 'system' and iconfig.k = 'docfile' and\n\t\ticonfig.v = '%s' and item_type = %d limit 1", dbesc($s), intval(ITEM_TYPE_DOC)); \Zotlabs\Lib\IConfig::Set($item, 'system', 'docfile', $s); if ($r) { $item['id'] = $r[0]['id']; $item['mid'] = $item['parent_mid'] = $r[0]['mid']; $x = item_store_update($item); } else { $item['mid'] = $item['parent_mid'] = item_message_id(); $x = item_store($item); } return $x; }
function post_is_importable($item, $abook) { if (!$abook) { return true; } if ($abook['abook_channel'] && !feature_enabled($abook['abook_channel'], 'connfilter')) { return true; } if (!$item) { return false; } if (!($abook['abook_incl'] || $abook['abook_excl'])) { return true; } require_once 'include/html2plain.php'; unobscure($item); $text = prepare_text($item['body'], $item['mimetype']); $text = html2plain($item['title'] ? $item['title'] . ' ' . $text : $text); $lang = null; if (strpos($abook['abook_incl'], 'lang=') !== false || strpos($abook['abook_excl'], 'lang=') !== false) { $lang = detect_language($text); } $tags = count($item['term']) ? $item['term'] : false; // exclude always has priority $exclude = $abook['abook_excl'] ? explode("\n", $abook['abook_excl']) : null; if ($exclude) { foreach ($exclude as $word) { $word = trim($word); if (!$word) { continue; } if (substr($word, 0, 1) === '#' && $tags) { foreach ($tags as $t) { if (($t['ttype'] == TERM_HASHTAG || $t['ttype'] == TERM_COMMUNITYTAG) && ($t['term'] === substr($word, 1) || substr($word, 1) === '*')) { return false; } } } elseif (strpos($word, '/') === 0 && preg_match($word, $text)) { return false; } elseif (strpos($word, 'lang=') === 0 && $lang && strcasecmp($lang, trim(substr($word, 5))) == 0) { return false; } elseif (stristr($text, $word) !== false) { return false; } } } $include = $abook['abook_incl'] ? explode("\n", $abook['abook_incl']) : null; if ($include) { foreach ($include as $word) { $word = trim($word); if (!$word) { continue; } if (substr($word, 0, 1) === '#' && $tags) { foreach ($tags as $t) { if (($t['ttype'] == TERM_HASHTAG || $t['ttype'] == TERM_COMMUNITYTAG) && ($t['term'] === substr($word, 1) || substr($word, 1) === '*')) { return true; } } } elseif (strpos($word, '/') === 0 && preg_match($word, $text)) { return true; } elseif (strpos($word, 'lang=') === 0 && $lang && strcasecmp($lang, trim(substr($word, 5))) == 0) { return true; } elseif (stristr($text, $word) !== false) { return true; } } } else { return true; } return false; }
function advanced_profile(&$a) { $o = ''; $uid = $a->profile['uid']; $o .= replace_macros(get_markup_template('section_title.tpl'), array('$title' => t('Profile'))); if ($a->profile['name']) { $tpl = get_markup_template('profile_advanced.tpl'); $profile = array(); $profile['fullname'] = array(t('Full Name:'), $a->profile['name']); if ($a->profile['gender']) { $profile['gender'] = array(t('Gender:'), $a->profile['gender']); } if ($a->profile['dob'] && $a->profile['dob'] != '0000-00-00') { $year_bd_format = t('j F, Y'); $short_bd_format = t('j F'); $val = intval($a->profile['dob']) ? day_translate(datetime_convert('UTC', 'UTC', $a->profile['dob'] . ' 00:00 +00:00', $year_bd_format)) : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format)); $profile['birthday'] = array(t('Birthday:'), $val); } if ($age = age($a->profile['dob'], $a->profile['timezone'], '')) { $profile['age'] = array(t('Age:'), $age); } if ($a->profile['marital']) { $profile['marital'] = array(t('Status:'), $a->profile['marital']); } if ($a->profile['with']) { $profile['marital']['with'] = $a->profile['with']; } if (strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') { $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s')); } if ($a->profile['sexual']) { $profile['sexual'] = array(t('Sexual Preference:'), $a->profile['sexual']); } if ($a->profile['homepage']) { $profile['homepage'] = array(t('Homepage:'), linkify($a->profile['homepage'])); } if ($a->profile['hometown']) { $profile['hometown'] = array(t('Hometown:'), linkify($a->profile['hometown'])); } if ($a->profile['pub_keywords']) { $profile['pub_keywords'] = array(t('Tags:'), $a->profile['pub_keywords']); } if ($a->profile['politic']) { $profile['politic'] = array(t('Political Views:'), $a->profile['politic']); } if ($a->profile['religion']) { $profile['religion'] = array(t('Religion:'), $a->profile['religion']); } if ($txt = prepare_text($a->profile['about'])) { $profile['about'] = array(t('About:'), $txt); } if ($txt = prepare_text($a->profile['interest'])) { $profile['interest'] = array(t('Hobbies/Interests:'), $txt); } if ($txt = prepare_text($a->profile['likes'])) { $profile['likes'] = array(t('Likes:'), $txt); } if ($txt = prepare_text($a->profile['dislikes'])) { $profile['dislikes'] = array(t('Dislikes:'), $txt); } if ($txt = prepare_text($a->profile['contact'])) { $profile['contact'] = array(t('Contact information and Social Networks:'), $txt); } if ($txt = prepare_text($a->profile['music'])) { $profile['music'] = array(t('Musical interests:'), $txt); } if ($txt = prepare_text($a->profile['book'])) { $profile['book'] = array(t('Books, literature:'), $txt); } if ($txt = prepare_text($a->profile['tv'])) { $profile['tv'] = array(t('Television:'), $txt); } if ($txt = prepare_text($a->profile['film'])) { $profile['film'] = array(t('Film/dance/culture/entertainment:'), $txt); } if ($txt = prepare_text($a->profile['romance'])) { $profile['romance'] = array(t('Love/Romance:'), $txt); } if ($txt = prepare_text($a->profile['work'])) { $profile['work'] = array(t('Work/employment:'), $txt); } if ($txt = prepare_text($a->profile['education'])) { $profile['education'] = array(t('School/education:'), $txt); } //show subcribed forum if it is enabled in the usersettings if (feature_enabled($uid, 'forumlist_profile')) { $profile['forumlist'] = array(t('Forums:'), forumlist_profile_advanced($uid)); } if ($a->profile['uid'] == local_user()) { $profile['edit'] = array($a->get_baseurl() . '/profiles/' . $a->profile['id'], t('Edit profile'), "", t('Edit profile')); } return replace_macros($tpl, array('$title' => t('Profile'), '$profile' => $profile)); } return ''; }
function prepare_body($item, $attach = false) { $a = get_app(); call_hooks('prepare_body_init', $item); $cache = get_config('system', 'itemcache'); if ($cache != '') { $cachefile = $cache . "/" . $item["guid"] . "-" . strtotime($item["edited"]) . "-" . hash("crc32", $item['body']); if (file_exists($cachefile)) { $s = file_get_contents($cachefile); } else { $s = prepare_text($item['body']); file_put_contents($cachefile, $s); } } else { $s = prepare_text($item['body']); } $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body', $prep_arr); $s = $prep_arr['html']; if (!$attach) { return $s; } $arr = explode(',', $item['attach']); if (count($arr)) { $s .= '<div class="body-attach">'; foreach ($arr as $r) { $matches = false; $icon = ''; $cnt = preg_match_all('|\\[attach\\]href=\\"(.*?)\\" length=\\"(.*?)\\" type=\\"(.*?)\\" title=\\"(.*?)\\"\\[\\/attach\\]|', $r, $matches, PREG_SET_ORDER); if ($cnt) { foreach ($matches as $mtch) { $icontype = strtolower(substr($mtch[3], 0, strpos($mtch[3], '/'))); switch ($icontype) { case 'video': case 'audio': case 'image': case 'text': $icon = '<div class="attachtype icon s22 type-' . $icontype . '"></div>'; break; default: $icon = '<div class="attachtype icon s22 type-unkn"></div>'; break; } $title = strlen(trim($mtch[4])) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1]); $title .= ' ' . $mtch[2] . ' ' . t('bytes'); if (local_user() == $item['uid'] && $item['contact-id'] != $a->contact['id']) { $the_url = $a->get_baseurl() . '/redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1]; } else { $the_url = $mtch[1]; } $s .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="external-link" >' . $icon . '</a>'; } } } $s .= '<div class="clear"></div></div>'; } $matches = false; $cnt = preg_match_all('/<(.*?)>/', $item['file'], $matches, PREG_SET_ORDER); if ($cnt) { // logger('prepare_text: categories: ' . print_r($matches,true), LOGGER_DEBUG); foreach ($matches as $mtch) { if (strlen($x)) { $x .= ','; } $x .= xmlify(file_tag_decode($mtch[1])) . (local_user() == $item['uid'] ? ' <a href="' . $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])) . '" title="' . t('remove') . '" >' . t('[remove]') . '</a>' : ''); } if (strlen($x)) { $s .= '<div class="categorytags"><span>' . t('Categories:') . ' </span>' . $x . '</div>'; } } $matches = false; $x = ''; $cnt = preg_match_all('/\\[(.*?)\\]/', $item['file'], $matches, PREG_SET_ORDER); if ($cnt) { // logger('prepare_text: filed_under: ' . print_r($matches,true), LOGGER_DEBUG); foreach ($matches as $mtch) { if (strlen($x)) { $x .= ' '; } $x .= xmlify(file_tag_decode($mtch[1])) . ' <a href="' . $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])) . '" title="' . t('remove') . '" >' . t('[remove]') . '</a>'; } if (strlen($x) && local_user() == $item['uid']) { $s .= '<div class="filesavetags"><span>' . t('Filed under:') . ' </span>' . $x . '</div>'; } } // Look for spoiler $spoilersearch = '<blockquote class="spoiler">'; // Remove line breaks before the spoiler while (strpos($s, "\n" . $spoilersearch) !== false) { $s = str_replace("\n" . $spoilersearch, $spoilersearch, $s); } while (strpos($s, "<br />" . $spoilersearch) !== false) { $s = str_replace("<br />" . $spoilersearch, $spoilersearch, $s); } while (strpos($s, $spoilersearch) !== false) { $pos = strpos($s, $spoilersearch); $rnd = random_string(8); $spoilerreplace = '<br /> <span id="spoiler-wrap-' . $rnd . '" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'spoiler-' . $rnd . '\');">' . sprintf(t('Click to open/close')) . '</span>' . '<blockquote class="spoiler" id="spoiler-' . $rnd . '" style="display: none;">'; $s = substr($s, 0, $pos) . $spoilerreplace . substr($s, $pos + strlen($spoilersearch)); } // Look for quote with author $authorsearch = '<blockquote class="author">'; while (strpos($s, $authorsearch) !== false) { $pos = strpos($s, $authorsearch); $rnd = random_string(8); $authorreplace = '<br /> <span id="author-wrap-' . $rnd . '" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'author-' . $rnd . '\');">' . sprintf(t('Click to open/close')) . '</span>' . '<blockquote class="author" id="author-' . $rnd . '" style="display: block;">'; $s = substr($s, 0, $pos) . $authorreplace . substr($s, $pos + strlen($authorsearch)); } $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body_final', $prep_arr); return $prep_arr['html']; }
function photos_content(&$a) { // URLs: // photos/name // photos/name/upload // photos/name/upload/xxxxx (xxxxx is album name) // photos/name/album/xxxxx // photos/name/album/xxxxx/edit // photos/name/image/xxxxx // photos/name/image/xxxxx/edit if (get_config('system', 'block_public') && !local_user() && !remote_user()) { notice(t('Public access denied.') . EOL); return; } require_once 'include/bbcode.php'; require_once 'include/security.php'; require_once 'include/conversation.php'; if (!x($a->data, 'channel')) { notice(t('No photos selected') . EOL); return; } $ph = photo_factory(''); $phototypes = $ph->supportedTypes(); $_SESSION['photo_return'] = $a->cmd; // // Parse arguments // $can_comment = perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'post_comments'); if (argc() > 3) { $datatype = argv(2); $datum = argv(3); } elseif (argc() > 2 && argv(2) === 'upload') { $datatype = 'upload'; } else { $datatype = 'summary'; } if (argc() > 4) { $cmd = argv(4); } else { $cmd = 'view'; } // // Setup permissions structures // $can_post = false; $visitor = 0; $owner_uid = $a->data['channel']['channel_id']; $owner_aid = $a->data['channel']['channel_account_id']; $observer = $a->get_observer(); $can_post = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'post_photos'); $can_view = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'view_photos'); if (!$can_view) { notice(t('Access to this item is restricted.') . EOL); return; } $sql_extra = permissions_sql($owner_uid); $o = ""; $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; // tabs $_is_owner = local_user() && local_user() == $owner_uid; $o .= profile_tabs($a, $_is_owner, $a->data['channel']['channel_address']); // // dispatch request // /** * Display upload form */ if ($datatype === 'upload') { if (!$can_post) { notice(t('Permission denied.')); return; } if (array_key_exists('albums', $a->data)) { $albums = get_app()->data['albums']; } else { $albums = photos_albums_list($a->data['channel'], $a->data['observer']); } $selname = $datum ? hex2bin($datum) : ''; $albumselect = '<select id="photos-upload-album-select" name="album" size="4">'; $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '> </option>'; if (count($albums['albums'])) { foreach ($albums['albums'] as $album) { if (!$album['text']) { continue; } $selected = $selname === $album['text'] ? ' selected="selected" ' : ''; $albumselect .= '<option value="' . $album['text'] . '"' . $selected . '>' . $album['text'] . '</option>'; } } $albumselect .= '</select>'; $uploader = ''; $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'], 'addon_text' => $uploader, 'default_upload' => true); call_hooks('photo_upload_form', $ret); $default_upload = '<input id="photos-upload-choose" type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" > <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>'; /* Show space usage */ $r = q("select sum(size) as total from photo where aid = %d and scale = 0 ", intval($a->data['channel']['channel_account_id'])); $limit = service_class_fetch($a->data['channel']['channel_id'], 'photo_upload_limit'); if ($limit !== false) { $usage_message = sprintf(t("You have used %1\$.2f Mbytes of %2\$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000); } else { $usage_message = sprintf(t('You have used %1$.2f Mbytes of photo storage.'), $r[0]['total'] / 1024000); } if ($_is_owner) { $channel = $a->get_channel(); $channel_acl = array('allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], 'deny_gid' => $channel['channel_deny_gid']); } $albumselect_e = $albumselect; $aclselect_e = $_is_owner ? populate_acl($channel_acl, false) : ''; $tpl = get_markup_template('photos_upload.tpl'); $o .= replace_macros($tpl, array('$pagename' => t('Upload Photos'), '$sessid' => session_id(), '$usage' => $usage_message, '$nickname' => $a->data['channel']['channel_address'], '$newalbum' => t('New album name: '), '$existalbumtext' => t('or existing album name: '), '$nosharetext' => t('Do not show a status post for this upload'), '$albumselect' => $albumselect_e, '$permissions' => t('Permissions'), '$aclselect' => $aclselect_e, '$uploader' => $ret['addon_text'], '$default' => $ret['default_upload'] ? $default_upload : '', '$uploadurl' => $ret['post_url'])); return $o; } /* * Display a single photo album */ if ($datatype === 'album') { if (strlen($datum) & 1 || !ctype_xdigit($datum)) { notice(t('Album name could not be decoded') . EOL); logger('mod_photos: illegal album encoding: ' . $datum); $datum = ''; } $album = hex2bin($datum); $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 and (photo_flags = %d or photo_flags = %d ) {$sql_extra} GROUP BY `resource_id`", intval($owner_uid), dbesc($album), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE)); if (count($r)) { $a->set_pager_total(count($r)); $a->set_pager_itemspage(60); } if ($_GET['order'] === 'posted') { $order = 'ASC'; } else { $order = 'DESC'; } $r = q("SELECT `resource_id`, `id`, `filename`, type, max(`scale`) AS `scale`, `description` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 and (photo_flags = %d or photo_flags = %d ) {$sql_extra} GROUP BY `resource_id` ORDER BY `created` {$order} LIMIT %d , %d", intval($owner_uid), dbesc($album), intvaL(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($a->pager['start']), intval($a->pager['itemspage'])); $o .= '<h3>' . $album . '</h3>'; if ($cmd === 'edit') { if ($album !== t('Profile Photos') && $album !== 'Contact Photos' && $album !== t('Contact Photos')) { if ($can_post) { if ($a->get_template_engine() === 'internal') { $album_e = template_escape($album); } else { $album_e = $album; } $edit_tpl = get_markup_template('album_edit.tpl'); $o .= replace_macros($edit_tpl, array('$nametext' => t('New album name: '), '$nickname' => $a->data['channel']['channel_address'], '$album' => $album_e, '$hexalbum' => bin2hex($album), '$submit' => t('Submit'), '$dropsubmit' => t('Delete Album'))); } } } else { if ($album !== t('Profile Photos') && $album !== 'Contact Photos' && $album !== t('Contact Photos')) { if ($can_post) { $o .= '<div id="album-edit-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($album) . '/edit' . '">' . t('Edit Album') . '</a></div>'; } } } if ($_GET['order'] === 'posted') { $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($album) . '" >' . t('Show Newest First') . '</a></div>'; } else { $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($album) . '?f=&order=posted" >' . t('Show Oldest First') . '</a></div>'; } if ($can_post) { $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/upload/' . bin2hex($album) . '" >' . t('Upload New Photos') . '</a></div>'; } $ajaxout = ''; $tpl = get_markup_template('photo_album.tpl'); if (count($r)) { $twist = 'rotright'; $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>"; $o .= '<div id="photo-album-contents">'; foreach ($r as $rr) { if ($twist == 'rotright') { $twist = 'rotleft'; } else { $twist = 'rotright'; } $ext = $phototypes[$rr['type']]; $imgalt_e = $rr['filename']; $desc_e = $rr['description']; // prettyphoto has potential license issues, so we can no longer include it in core // The following lines would need to be modified so that they are provided in theme specific files // instead of core modules for themes that wish to make use of prettyphoto. I would suggest // the feature as a per-theme display option and putting the rel line inside a template. // if(feature_enabled($a->data['channel']['channel_id'],'prettyphoto')){ // $imagelink = ($a->get_baseurl() . '/photo/' . $rr['resource_id'] . '.' . $ext ); // $rel=("prettyPhoto[pp_gal]"); // } // else { $imagelink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : ''); $rel = "photo"; // } $tmp = replace_macros($tpl, array('$id' => $rr['id'], '$twist' => ' ' . $twist . rand(2, 4), '$photolink' => $imagelink, '$rel' => $rel, '$phototitle' => t('View Photo'), '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . $rr['scale'] . '.' . $ext, '$imgalt' => $imgalt_e, '$desc' => $desc_e, '$ext' => $ext, '$hash' => $rr['resource_id'])); if ($_REQUEST['aj']) { $ajaxout .= $tmp; } else { $o .= $tmp; } } } if ($_REQUEST['aj']) { if (!$r) { $ajaxout .= '<div id="content-complete"></div>'; } echo $ajaxout; killme(); } $o .= '<div id="page-end"></div>'; $o .= '</div>'; // photo-album-contents $o .= '<div id="photo-album-end"></div>'; $o .= '<script>$(document).ready(function() { loadingPage = false;});</script>'; $o .= '<div id="page-spinner"></div>'; // $o .= paginate($a); return $o; } /** * Display one photo */ if ($datatype === 'image') { // fetch image, item containing image, then comments $ph = q("SELECT aid,uid,xchan,resource_id,created,edited,title,`description`,album,filename,`type`,height,width,`size`,scale,profile,photo_flags,allow_cid,allow_gid,deny_cid,deny_gid FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' \n\t\t\tand (photo_flags = %d or photo_flags = %d ) {$sql_extra} ORDER BY `scale` ASC ", intval($owner_uid), dbesc($datum), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE)); if (!$ph) { /* Check again - this time without specifying permissions */ $ph = q("SELECT id FROM photo WHERE uid = %d AND resource_id = '%s' \n\t\t\t\tand ( photo_flags = %d or photo_flags = %d )\n\t\t\t\tLIMIT 1", intval($owner_uid), dbesc($datum), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE)); if ($ph) { notice(t('Permission denied. Access to this item may be restricted.') . EOL); } else { notice(t('Photo not available') . EOL); } return; } $prevlink = ''; $nextlink = ''; if ($_GET['order'] === 'posted') { $order = 'ASC'; } else { $order = 'DESC'; } $prvnxt = q("SELECT `resource_id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0 \n\t\t\tand ( photo_flags = %d or photo_flags = %d ) {$sql_extra} ORDER BY `created` {$order} ", dbesc($ph[0]['album']), intval($owner_uid), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE)); if (count($prvnxt)) { for ($z = 0; $z < count($prvnxt); $z++) { if ($prvnxt[$z]['resource_id'] == $ph[0]['resource_id']) { $prv = $z - 1; $nxt = $z + 1; if ($prv < 0) { $prv = count($prvnxt) - 1; } if ($nxt >= count($prvnxt)) { $nxt = 0; } break; } } $prevlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$prv]['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : ''); $nextlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$nxt]['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : ''); } if (count($ph) == 1) { $hires = $lores = $ph[0]; } if (count($ph) > 1) { if ($ph[1]['scale'] == 2) { // original is 640 or less, we can display it directly $hires = $lores = $ph[0]; } else { $hires = $ph[0]; $lores = $ph[1]; } } $album_link = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($ph[0]['album']); $tools = Null; $lock = Null; if ($can_post && $ph[0]['uid'] == $owner_uid) { $tools = array('profile' => array($a->get_baseurl() . '/profile_photo/use/' . $ph[0]['resource_id'], t('Use as profile photo'))); // lock $lock = $ph[0]['uid'] == local_user() && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) ? t('Private Message') : Null; } $a->page['htmlhead'] .= '<script>$(document).keydown(function(event) {' . "\n"; if ($prevlink) { $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = \'' . $prevlink . '\'; }' . "\n"; } if ($nextlink) { $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = \'' . $nextlink . '\'; }' . "\n"; } $a->page['htmlhead'] .= '});</script>'; if ($prevlink) { $prevlink = array($prevlink, '<i class="icon-backward photo-icons""></i>'); } $photo = array('href' => $a->get_baseurl() . '/photo/' . $hires['resource_id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']], 'title' => t('View Full Size'), 'src' => $a->get_baseurl() . '/photo/' . $lores['resource_id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('', '', '', 'ymdhis')); if ($nextlink) { $nextlink = array($nextlink, '<i class="icon-forward photo-icons"></i>'); } // Do we have an item for this photo? $linked_items = q("SELECT * FROM item WHERE resource_id = '%s' and resource_type = 'photo' \n\t\t\t{$sql_extra} LIMIT 1", dbesc($datum)); if ($linked_items) { xchan_query($linked_items); $linked_items = fetch_post_tags($linked_items, true); $link_item = $linked_items[0]; $r = q("select * from item where parent_mid = '%s' \n\t\t\t\tand item_restrict = 0 and uid = %d {$sql_extra} ", dbesc($link_item['mid']), intval($link_item['uid'])); if ($r) { xchan_query($r); $r = fetch_post_tags($r, true); $r = conv_sort($r, 'commented'); } $tags = array(); if ($link_item['term']) { $cnt = 0; foreach ($link_item['term'] as $t) { $tags[$cnt] = array(0 => format_term_for_display($t)); } if ($can_post && $ph[0]['uid'] == $owner_uid) { $tags[$cnt][1] = 'tagrm?f=&item=' . $link_item['id']; $tags[$cnt][2] = t('Remove'); } $cnt++; } if (local_user() && local_user() == $link_item['uid']) { q("UPDATE `item` SET item_flags = (item_flags ^ %d) WHERE parent = %d and uid = %d and (item_flags & %d)", intval(ITEM_UNSEEN), intval($link_item['parent']), intval(local_user()), intval(ITEM_UNSEEN)); } } // logger('mod_photo: link_item' . print_r($link_item,true)); // FIXME - remove this when we move to conversation module $r = $r[0]['children']; $edit = null; if ($can_post) { if (array_key_exists('albums', $a->data)) { $albums = get_app()->data['albums']; } else { $albums = photos_albums_list($a->data['channel'], $a->data['observer']); } $album_e = $ph[0]['album']; $caption_e = $ph[0]['description']; $aclselect_e = populate_acl($ph[0]); $edit = array('edit' => t('Edit photo'), 'id' => $ph[0]['id'], 'rotatecw' => t('Rotate CW (right)'), 'rotateccw' => t('Rotate CCW (left)'), 'albums' => $albums['albums'], 'album' => $album_e, 'newalbum' => t('New album name'), 'nickname' => $a->data['channel']['channel_address'], 'resource_id' => $ph[0]['resource_id'], 'capt_label' => t('Caption'), 'caption' => $caption_e, 'tag_label' => t('Add a Tag'), 'permissions' => t('Permissions'), 'aclselect' => $aclselect_e, 'help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'), 'item_id' => count($linked_items) ? $link_item['id'] : 0, 'submit' => t('Submit'), 'delete' => t('Delete Photo')); } if (count($linked_items)) { $cmnt_tpl = get_markup_template('comment_item.tpl'); $tpl = get_markup_template('photo_item.tpl'); $return_url = $a->cmd; $like_tpl = get_markup_template('like_noshare.tpl'); $likebuttons = ''; if ($can_post || $can_comment) { $likebuttons = replace_macros($like_tpl, array('$id' => $link_item['id'], '$likethis' => t("I like this (toggle)"), '$nolike' => t("I don't like this (toggle)"), '$share' => t('Share'), '$wait' => t('Please wait'))); } $comments = ''; if (!count($r)) { if ($can_post || $can_comment) { $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$mode' => 'photos', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $observer['xchan_url'], '$mytitle' => t('This is you'), '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$ww' => '', '$feature_encrypt' => false)); } } $alike = array(); $dlike = array(); $like = ''; $dislike = ''; // display comments if ($r) { foreach ($r as $item) { like_puller($a, $item, $alike, 'like'); like_puller($a, $item, $dlike, 'dislike'); } $like = isset($alike[$link_item['id']]) ? format_like($alike[$link_item['id']], $alike[$link_item['id'] . '-l'], 'like', $link_item['id']) : ''; $dislike = isset($dlike[$link_item['id']]) ? format_like($dlike[$link_item['id']], $dlike[$link_item['id'] . '-l'], 'dislike', $link_item['id']) : ''; foreach ($r as $item) { $comment = ''; $template = $tpl; $sparkle = ''; if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) { continue; } $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid']; $profile_url = zid($item['author']['xchan_url']); $sparkle = ''; $profile_name = $item['author']['xchan_name']; $profile_avatar = $item['author']['xchan_photo_m']; $profile_link = $profile_url; $drop = ''; if ($observer['xchan_hash'] === $item['author_xchan'] || $observer['xchan_hash'] === $item['owner_xchan']) { $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete'))); } $name_e = $profile_name; $title_e = $item['title']; unobscure($item); $body_e = prepare_text($item['body'], $item['mimetype']); $comments .= replace_macros($template, array('$id' => $item['item_id'], '$mode' => 'photos', '$profile_url' => $profile_link, '$name' => $name_e, '$thumb' => $profile_avatar, '$sparkle' => $sparkle, '$title' => $title_e, '$body' => $body_e, '$ago' => relative_date($item['created']), '$indent' => $item['parent'] != $item['item_id'] ? ' comment' : '', '$drop' => $drop, '$comment' => $comment)); } if ($can_post || $can_comment) { $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $observer['xchan_url'], '$mytitle' => t('This is you'), '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$ww' => '')); } } $paginate = paginate($a); } $album_e = array($album_link, $ph[0]['album']); $like_e = $like; $dislike_e = $dislike; $photo_tpl = get_markup_template('photo_view.tpl'); $o .= replace_macros($photo_tpl, array('$id' => $ph[0]['id'], '$album' => $album_e, '$tools' => $tools, '$lock' => $lock, '$photo' => $photo, '$prevlink' => $prevlink, '$nextlink' => $nextlink, '$desc' => $ph[0]['description'], '$tag_hdr' => t('In This Photo:'), '$tags' => $tags, '$edit' => $edit, '$likebuttons' => $likebuttons, '$like' => $like_e, '$dislike' => $dislike_e, '$comments' => $comments, '$paginate' => $paginate)); $a->data['photo_html'] = $o; return $o; } // Default - show recent photos with upload link (if applicable) //$o = ''; $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' \n\t\tand ( photo_flags = %d or photo_flags = %d ) {$sql_extra} GROUP BY `resource_id`", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE)); if (count($r)) { $a->set_pager_total(count($r)); $a->set_pager_itemspage(60); } $r = q("SELECT `resource_id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`\n\t\tWHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'\n\t\tand ( photo_flags = %d or photo_flags = %d ) \n\t\t{$sql_extra} GROUP BY `resource_id` ORDER BY `created` DESC LIMIT %d , %d", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($a->pager['start']), intval($a->pager['itemspage'])); $photos = array(); if (count($r)) { $twist = 'rotright'; foreach ($r as $rr) { if ($twist == 'rotright') { $twist = 'rotleft'; } else { $twist = 'rotright'; } $ext = $phototypes[$rr['type']]; if ($a->get_template_engine() === 'internal') { $alt_e = template_escape($rr['filename']); $name_e = template_escape($rr['album']); } else { $alt_e = $rr['filename']; $name_e = $rr['album']; } $photos[] = array('id' => $rr['id'], 'twist' => ' ' . $twist . rand(2, 4), 'link' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'], 'title' => t('View Photo'), 'src' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . ($rr['scale'] == 6 ? 4 : $rr['scale']) . '.' . $ext, 'alt' => $alt_e, 'album' => array('link' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($rr['album']), 'name' => $name_e, 'alt' => t('View Album'))); } } if ($_REQUEST['aj']) { if ($photos) { $o = replace_macros(get_markup_template('photosajax.tpl'), array('$photos' => $photos)); } else { $o = '<div id="content-complete"></div>'; } echo $o; killme(); } else { $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>"; $tpl = get_markup_template('photos_recent.tpl'); $o .= replace_macros($tpl, array('$title' => t('Recent Photos'), '$can_post' => $can_post, '$upload' => array(t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/upload'), '$photos' => $photos)); } if (!$photos && $_REQUEST['aj']) { $o .= '<div id="content-complete"></div>'; echo $o; killme(); } // $o .= paginate($a); return $o; }
function item_store($arr, $force_parent = false) { // If a Diaspora signature structure was passed in, pull it out of the // item array and set it aside for later storage. $dsprsig = null; if (x($arr, 'dsprsig')) { $dsprsig = json_decode(base64_decode($arr['dsprsig'])); unset($arr['dsprsig']); } // if an OStatus conversation url was passed in, it is stored and then // removed from the array. $ostatus_conversation = null; if (isset($arr["ostatus_conversation"])) { $ostatus_conversation = $arr["ostatus_conversation"]; unset($arr["ostatus_conversation"]); } if (x($arr, 'gravity')) { $arr['gravity'] = intval($arr['gravity']); } elseif ($arr['parent-uri'] === $arr['uri']) { $arr['gravity'] = 0; } elseif (activity_match($arr['verb'], ACTIVITY_POST)) { $arr['gravity'] = 6; } else { $arr['gravity'] = 6; } // extensible catchall if (!x($arr, 'type')) { $arr['type'] = 'remote'; } // Shouldn't happen but we want to make absolutely sure it doesn't leak from a plugin. if (strpos($arr['body'], '<') !== false || strpos($arr['body'], '>') !== false) { $arr['body'] = strip_tags($arr['body']); } if (version_compare(PHP_VERSION, '5.3.0', '>=')) { require_once 'library/langdet/Text/LanguageDetect.php'; $naked_body = preg_replace('/\\[(.+?)\\]/', '', $arr['body']); $l = new Text_LanguageDetect(); //$lng = $l->detectConfidence($naked_body); //$arr['postopts'] = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : ''); $lng = $l->detect($naked_body, 3); if (sizeof($lng) > 0) { $postopts = ""; foreach ($lng as $language => $score) { if ($postopts == "") { $postopts = "lang="; } else { $postopts .= ":"; } $postopts .= $language . ";" . $score; } $arr['postopts'] = $postopts; } } $arr['wall'] = x($arr, 'wall') ? intval($arr['wall']) : 0; $arr['uri'] = x($arr, 'uri') ? notags(trim($arr['uri'])) : random_string(); $arr['extid'] = x($arr, 'extid') ? notags(trim($arr['extid'])) : ''; $arr['author-name'] = x($arr, 'author-name') ? notags(trim($arr['author-name'])) : ''; $arr['author-link'] = x($arr, 'author-link') ? notags(trim($arr['author-link'])) : ''; $arr['author-avatar'] = x($arr, 'author-avatar') ? notags(trim($arr['author-avatar'])) : ''; $arr['owner-name'] = x($arr, 'owner-name') ? notags(trim($arr['owner-name'])) : ''; $arr['owner-link'] = x($arr, 'owner-link') ? notags(trim($arr['owner-link'])) : ''; $arr['owner-avatar'] = x($arr, 'owner-avatar') ? notags(trim($arr['owner-avatar'])) : ''; $arr['created'] = x($arr, 'created') !== false ? datetime_convert('UTC', 'UTC', $arr['created']) : datetime_convert(); $arr['edited'] = x($arr, 'edited') !== false ? datetime_convert('UTC', 'UTC', $arr['edited']) : datetime_convert(); $arr['commented'] = datetime_convert(); $arr['received'] = datetime_convert(); $arr['changed'] = datetime_convert(); $arr['title'] = x($arr, 'title') ? notags(trim($arr['title'])) : ''; $arr['location'] = x($arr, 'location') ? notags(trim($arr['location'])) : ''; $arr['coord'] = x($arr, 'coord') ? notags(trim($arr['coord'])) : ''; $arr['last-child'] = x($arr, 'last-child') ? intval($arr['last-child']) : 0; $arr['visible'] = x($arr, 'visible') !== false ? intval($arr['visible']) : 1; $arr['deleted'] = 0; $arr['parent-uri'] = x($arr, 'parent-uri') ? notags(trim($arr['parent-uri'])) : ''; $arr['verb'] = x($arr, 'verb') ? notags(trim($arr['verb'])) : ''; $arr['object-type'] = x($arr, 'object-type') ? notags(trim($arr['object-type'])) : ''; $arr['object'] = x($arr, 'object') ? trim($arr['object']) : ''; $arr['target-type'] = x($arr, 'target-type') ? notags(trim($arr['target-type'])) : ''; $arr['target'] = x($arr, 'target') ? trim($arr['target']) : ''; $arr['plink'] = x($arr, 'plink') ? notags(trim($arr['plink'])) : ''; $arr['allow_cid'] = x($arr, 'allow_cid') ? trim($arr['allow_cid']) : ''; $arr['allow_gid'] = x($arr, 'allow_gid') ? trim($arr['allow_gid']) : ''; $arr['deny_cid'] = x($arr, 'deny_cid') ? trim($arr['deny_cid']) : ''; $arr['deny_gid'] = x($arr, 'deny_gid') ? trim($arr['deny_gid']) : ''; $arr['private'] = x($arr, 'private') ? intval($arr['private']) : 0; $arr['bookmark'] = x($arr, 'bookmark') ? intval($arr['bookmark']) : 0; $arr['body'] = x($arr, 'body') ? trim($arr['body']) : ''; $arr['tag'] = x($arr, 'tag') ? notags(trim($arr['tag'])) : ''; $arr['attach'] = x($arr, 'attach') ? notags(trim($arr['attach'])) : ''; $arr['app'] = x($arr, 'app') ? notags(trim($arr['app'])) : ''; $arr['origin'] = x($arr, 'origin') ? intval($arr['origin']) : 0; $arr['guid'] = x($arr, 'guid') ? notags(trim($arr['guid'])) : get_guid(); $arr['thr-parent'] = $arr['parent-uri']; if ($arr['parent-uri'] === $arr['uri']) { $parent_id = 0; $parent_deleted = 0; $allow_cid = $arr['allow_cid']; $allow_gid = $arr['allow_gid']; $deny_cid = $arr['deny_cid']; $deny_gid = $arr['deny_gid']; } else { // find the parent and snarf the item id and ACLs // and anything else we need to inherit $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d ORDER BY `id` ASC LIMIT 1", dbesc($arr['parent-uri']), intval($arr['uid'])); if (count($r)) { // is the new message multi-level threaded? // even though we don't support it now, preserve the info // and re-attach to the conversation parent. if ($r[0]['uri'] != $r[0]['parent-uri']) { $arr['parent-uri'] = $r[0]['parent-uri']; $z = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `parent-uri` = '%s' AND `uid` = %d \n\t\t\t\t\tORDER BY `id` ASC LIMIT 1", dbesc($r[0]['parent-uri']), dbesc($r[0]['parent-uri']), intval($arr['uid'])); if ($z && count($z)) { $r = $z; } } $parent_id = $r[0]['id']; $parent_deleted = $r[0]['deleted']; $allow_cid = $r[0]['allow_cid']; $allow_gid = $r[0]['allow_gid']; $deny_cid = $r[0]['deny_cid']; $deny_gid = $r[0]['deny_gid']; $arr['wall'] = $r[0]['wall']; // if the parent is private, force privacy for the entire conversation // This differs from the above settings as it subtly allows comments from // email correspondents to be private even if the overall thread is not. if ($r[0]['private']) { $arr['private'] = $r[0]['private']; } // Edge case. We host a public forum that was originally posted to privately. // The original author commented, but as this is a comment, the permissions // weren't fixed up so it will still show the comment as private unless we fix it here. if (intval($r[0]['forum_mode']) == 1 && !$r[0]['private']) { $arr['private'] = 0; } } else { // Allow one to see reply tweets from status.net even when // we don't have or can't see the original post. if ($force_parent) { logger('item_store: $force_parent=true, reply converted to top-level post.'); $parent_id = 0; $arr['parent-uri'] = $arr['uri']; $arr['gravity'] = 0; } else { logger('item_store: item parent was not found - ignoring item'); return 0; } $parent_deleted = 0; } } $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($arr['uri']), intval($arr['uid'])); if ($r && count($r)) { logger('item-store: duplicate item ignored. ' . print_r($arr, true)); return 0; } call_hooks('post_remote', $arr); if (x($arr, 'cancel')) { logger('item_store: post cancelled by plugin.'); return 0; } dbesc_array($arr); logger('item_store: ' . print_r($arr, true), LOGGER_DATA); $r = dbq("INSERT INTO `item` (`" . implode("`, `", array_keys($arr)) . "`) VALUES ('" . implode("', '", array_values($arr)) . "')"); // find the item we just created $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d ORDER BY `id` ASC ", $arr['uri'], intval($arr['uid'])); if (count($r)) { $current_post = $r[0]['id']; logger('item_store: created item ' . $current_post); create_tags_from_item($r[0]['id']); } else { logger('item_store: could not locate created item'); return 0; } if (count($r) > 1) { logger('item_store: duplicated post occurred. Removing duplicates.'); q("DELETE FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `id` != %d ", $arr['uri'], intval($arr['uid']), intval($current_post)); } if (!$parent_id || $arr['parent-uri'] === $arr['uri']) { $parent_id = $current_post; } if (strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid)) { $private = 1; } else { $private = $arr['private']; } // Set parent id - and also make sure to inherit the parent's ACL's. $r = q("UPDATE `item` SET `parent` = %d, `allow_cid` = '%s', `allow_gid` = '%s',\n\t\t`deny_cid` = '%s', `deny_gid` = '%s', `private` = %d, `deleted` = %d WHERE `id` = %d LIMIT 1", intval($parent_id), dbesc($allow_cid), dbesc($allow_gid), dbesc($deny_cid), dbesc($deny_gid), intval($private), intval($parent_deleted), intval($current_post)); create_tags_from_item($current_post); // Complete ostatus threads if ($ostatus_conversation) { complete_conversation($current_post, $ostatus_conversation); } $arr['id'] = $current_post; $arr['parent'] = $parent_id; $arr['allow_cid'] = $allow_cid; $arr['allow_gid'] = $allow_gid; $arr['deny_cid'] = $deny_cid; $arr['deny_gid'] = $deny_gid; $arr['private'] = $private; $arr['deleted'] = $parent_deleted; // update the commented timestamp on the parent q("UPDATE `item` set `commented` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), dbesc(datetime_convert()), intval($parent_id)); if ($dsprsig) { q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", intval($current_post), dbesc($dsprsig->signed_text), dbesc($dsprsig->signature), dbesc($dsprsig->signer)); } /** * If this is now the last-child, force all _other_ children of this parent to *not* be last-child */ if ($arr['last-child']) { $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d AND `id` != %d", dbesc($arr['uri']), intval($arr['uid']), intval($current_post)); } tag_deliver($arr['uid'], $current_post); // Store the fresh generated item into the cache $cachefile = get_cachefile($arr["guid"] . "-" . hash("md5", $arr['body'])); if ($cachefile != '' and !file_exists($cachefile)) { $s = prepare_text($arr['body']); $a = get_app(); $stamp1 = microtime(true); file_put_contents($cachefile, $s); $a->save_timestamp($stamp1, "file"); logger('item_store: put item ' . $current_post . ' into cachefile ' . $cachefile); } $r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post)); if (count($r) == 1) { call_hooks('post_remote_end', $r[0]); } else { logger('item_store: new item not found in DB, id ' . $current_post); } return $current_post; }
function advanced_profile(&$a) { $o .= ''; $o .= '<h2>' . t('Profile') . '</h2>'; if ($a->profile['name']) { $tpl = get_markup_template('profile_advanced.tpl'); $profile = array(); $profile['fullname'] = array(t('Full Name:'), $a->profile['name']); if ($a->profile['gender']) { $profile['gender'] = array(t('Gender:'), $a->profile['gender']); } if ($a->profile['dob'] && $a->profile['dob'] != '0000-00-00') { $year_bd_format = t('j F, Y'); $short_bd_format = t('j F'); $val = intval($a->profile['dob']) ? day_translate(datetime_convert('UTC', 'UTC', $a->profile['dob'] . ' 00:00 +00:00', $year_bd_format)) : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr($a->profile['dob'], 6) . ' 00:00 +00:00', $short_bd_format)); $profile['birthday'] = array(t('Birthday:'), $val); } if ($age = age($a->profile['dob'], $a->profile['timezone'], '')) { $profile['age'] = array(t('Age:'), $age); } if ($a->profile['marital']) { $profile['marital'] = array(t('Status:'), $a->profile['marital']); } if ($a->profile['with']) { $profile['marital']['with'] = $a->profile['with']; } if ($a->profile['sexual']) { $profile['sexual'] = array(t('Sexual Preference:'), $a->profile['sexual']); } if ($a->profile['homepage']) { $profile['homepage'] = array(t('Homepage:'), linkify($a->profile['homepage'])); } if ($a->profile['pub_keywords']) { $profile['pub_keywords'] = array(t('Tags:'), $a->profile['pub_keywords']); } if ($a->profile['politic']) { $profile['politic'] = array(t('Political Views:'), $a->profile['politic']); } if ($a->profile['religion']) { $profile['religion'] = array(t('Religion:'), $a->profile['religion']); } if ($txt = prepare_text($a->profile['about'])) { $profile['about'] = array(t('About:'), $txt); } if ($txt = prepare_text($a->profile['interest'])) { $profile['interest'] = array(t('Hobbies/Interests:'), $txt); } if ($txt = prepare_text($a->profile['contact'])) { $profile['contact'] = array(t('Contact information and Social Networks:'), $txt); } if ($txt = prepare_text($a->profile['music'])) { $profile['music'] = array(t('Musical interests:'), $txt); } if ($txt = prepare_text($a->profile['book'])) { $profile['book'] = array(t('Books, literature:'), $txt); } if ($txt = prepare_text($a->profile['tv'])) { $profile['tv'] = array(t('Television:'), $txt); } if ($txt = prepare_text($a->profile['film'])) { $profile['film'] = array(t('Film/dance/culture/entertainment:'), $txt); } if ($txt = prepare_text($a->profile['romance'])) { $profile['romance'] = array(t('Love/Romance:'), $txt); } if ($txt = prepare_text($a->profile['work'])) { $profile['work'] = array(t('Work/employment:'), $txt); } if ($txt = prepare_text($a->profile['education'])) { $profile['education'] = array(t('School/education:'), $txt); } } return replace_macros($tpl, array('$title' => t('Profile'), '$profile' => $profile)); }
function item_store($arr, $force_parent = false, $notify = false) { // If it is a posting where users should get notifications, then define it as wall posting if ($notify) { $arr['wall'] = 1; $arr['type'] = 'wall'; $arr['origin'] = 1; $arr['last-child'] = 1; $arr['network'] = NETWORK_DFRN; } // If a Diaspora signature structure was passed in, pull it out of the // item array and set it aside for later storage. $dsprsig = null; if (x($arr, 'dsprsig')) { $dsprsig = json_decode(base64_decode($arr['dsprsig'])); unset($arr['dsprsig']); } // if an OStatus conversation url was passed in, it is stored and then // removed from the array. $ostatus_conversation = null; if (isset($arr["ostatus_conversation"])) { $ostatus_conversation = $arr["ostatus_conversation"]; unset($arr["ostatus_conversation"]); } if (x($arr, 'gravity')) { $arr['gravity'] = intval($arr['gravity']); } elseif ($arr['parent-uri'] === $arr['uri']) { $arr['gravity'] = 0; } elseif (activity_match($arr['verb'], ACTIVITY_POST)) { $arr['gravity'] = 6; } else { $arr['gravity'] = 6; } // extensible catchall if (!x($arr, 'type')) { $arr['type'] = 'remote'; } /* check for create date and expire time */ $uid = intval($arr['uid']); $r = q("SELECT expire FROM user WHERE uid = %d", $uid); if (count($r)) { $expire_interval = $r[0]['expire']; if ($expire_interval > 0) { $expire_date = new DateTime('- ' . $expire_interval . ' days', new DateTimeZone('UTC')); $created_date = new DateTime($arr['created'], new DateTimeZone('UTC')); if ($created_date < $expire_date) { logger('item-store: item created (' . $arr['created'] . ') before expiration time (' . $expire_date->format(DateTime::W3C) . '). ignored. ' . print_r($arr, true), LOGGER_DEBUG); return 0; } } } // If there is no guid then take the same guid that was taken before for the same uri if (trim($arr['guid']) == "" and trim($arr['uri']) != "") { logger('item_store: checking for an existing guid for uri ' . $arr['uri'], LOGGER_DEBUG); $r = q("SELECT `guid` FROM `item` WHERE `uri` = '%s' AND `guid` != '' LIMIT 1", dbesc(trim($arr['uri']))); if (count($r)) { $arr['guid'] = $r[0]["guid"]; logger('item_store: found guid ' . $arr['guid'] . ' for uri ' . $arr['uri'], LOGGER_DEBUG); } } // Shouldn't happen but we want to make absolutely sure it doesn't leak from a plugin. // Deactivated, since the bbcode parser can handle with it - and it destroys posts with some smileys that contain "<" //if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) // $arr['body'] = strip_tags($arr['body']); if (version_compare(PHP_VERSION, '5.3.0', '>=')) { require_once 'library/langdet/Text/LanguageDetect.php'; $naked_body = preg_replace('/\\[(.+?)\\]/', '', $arr['body']); $l = new Text_LanguageDetect(); //$lng = $l->detectConfidence($naked_body); //$arr['postopts'] = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : ''); $lng = $l->detect($naked_body, 3); if (sizeof($lng) > 0) { $postopts = ""; foreach ($lng as $language => $score) { if ($postopts == "") { $postopts = "lang="; } else { $postopts .= ":"; } $postopts .= $language . ";" . $score; } $arr['postopts'] = $postopts; } } $arr['wall'] = x($arr, 'wall') ? intval($arr['wall']) : 0; $arr['uri'] = x($arr, 'uri') ? notags(trim($arr['uri'])) : random_string(); $arr['extid'] = x($arr, 'extid') ? notags(trim($arr['extid'])) : ''; $arr['author-name'] = x($arr, 'author-name') ? notags(trim($arr['author-name'])) : ''; $arr['author-link'] = x($arr, 'author-link') ? notags(trim($arr['author-link'])) : ''; $arr['author-avatar'] = x($arr, 'author-avatar') ? notags(trim($arr['author-avatar'])) : ''; $arr['owner-name'] = x($arr, 'owner-name') ? notags(trim($arr['owner-name'])) : ''; $arr['owner-link'] = x($arr, 'owner-link') ? notags(trim($arr['owner-link'])) : ''; $arr['owner-avatar'] = x($arr, 'owner-avatar') ? notags(trim($arr['owner-avatar'])) : ''; $arr['created'] = x($arr, 'created') !== false ? datetime_convert('UTC', 'UTC', $arr['created']) : datetime_convert(); $arr['edited'] = x($arr, 'edited') !== false ? datetime_convert('UTC', 'UTC', $arr['edited']) : datetime_convert(); $arr['commented'] = datetime_convert(); $arr['received'] = datetime_convert(); $arr['changed'] = datetime_convert(); $arr['title'] = x($arr, 'title') ? notags(trim($arr['title'])) : ''; $arr['location'] = x($arr, 'location') ? notags(trim($arr['location'])) : ''; $arr['coord'] = x($arr, 'coord') ? notags(trim($arr['coord'])) : ''; $arr['last-child'] = x($arr, 'last-child') ? intval($arr['last-child']) : 0; $arr['visible'] = x($arr, 'visible') !== false ? intval($arr['visible']) : 1; $arr['deleted'] = 0; $arr['parent-uri'] = x($arr, 'parent-uri') ? notags(trim($arr['parent-uri'])) : ''; $arr['verb'] = x($arr, 'verb') ? notags(trim($arr['verb'])) : ''; $arr['object-type'] = x($arr, 'object-type') ? notags(trim($arr['object-type'])) : ''; $arr['object'] = x($arr, 'object') ? trim($arr['object']) : ''; $arr['target-type'] = x($arr, 'target-type') ? notags(trim($arr['target-type'])) : ''; $arr['target'] = x($arr, 'target') ? trim($arr['target']) : ''; $arr['plink'] = x($arr, 'plink') ? notags(trim($arr['plink'])) : ''; $arr['allow_cid'] = x($arr, 'allow_cid') ? trim($arr['allow_cid']) : ''; $arr['allow_gid'] = x($arr, 'allow_gid') ? trim($arr['allow_gid']) : ''; $arr['deny_cid'] = x($arr, 'deny_cid') ? trim($arr['deny_cid']) : ''; $arr['deny_gid'] = x($arr, 'deny_gid') ? trim($arr['deny_gid']) : ''; $arr['private'] = x($arr, 'private') ? intval($arr['private']) : 0; $arr['bookmark'] = x($arr, 'bookmark') ? intval($arr['bookmark']) : 0; $arr['body'] = x($arr, 'body') ? trim($arr['body']) : ''; $arr['tag'] = x($arr, 'tag') ? notags(trim($arr['tag'])) : ''; $arr['attach'] = x($arr, 'attach') ? notags(trim($arr['attach'])) : ''; $arr['app'] = x($arr, 'app') ? notags(trim($arr['app'])) : ''; $arr['origin'] = x($arr, 'origin') ? intval($arr['origin']) : 0; $arr['guid'] = x($arr, 'guid') ? notags(trim($arr['guid'])) : get_guid(30); $arr['network'] = x($arr, 'network') ? trim($arr['network']) : ''; if ($arr['plink'] == "") { $a = get_app(); $arr['plink'] = $a->get_baseurl() . '/display/' . urlencode($arr['guid']); } if ($arr['network'] == "") { $r = q("SELECT `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($arr['contact-id']), intval($arr['uid'])); if (count($r)) { $arr['network'] = $r[0]["network"]; } // Fallback to friendica (why is it empty in some cases?) if ($arr['network'] == "") { $arr['network'] = NETWORK_DFRN; } logger("item_store: Set network to " . $arr["network"] . " for " . $arr["uri"], LOGGER_DEBUG); } $arr['thr-parent'] = $arr['parent-uri']; if ($arr['parent-uri'] === $arr['uri']) { $parent_id = 0; $parent_deleted = 0; $allow_cid = $arr['allow_cid']; $allow_gid = $arr['allow_gid']; $deny_cid = $arr['deny_cid']; $deny_gid = $arr['deny_gid']; $notify_type = 'wall-new'; } else { // find the parent and snarf the item id and ACLs // and anything else we need to inherit $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d ORDER BY `id` ASC LIMIT 1", dbesc($arr['parent-uri']), intval($arr['uid'])); if (count($r)) { // is the new message multi-level threaded? // even though we don't support it now, preserve the info // and re-attach to the conversation parent. if ($r[0]['uri'] != $r[0]['parent-uri']) { $arr['parent-uri'] = $r[0]['parent-uri']; $z = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `parent-uri` = '%s' AND `uid` = %d\n\t\t\t\t\tORDER BY `id` ASC LIMIT 1", dbesc($r[0]['parent-uri']), dbesc($r[0]['parent-uri']), intval($arr['uid'])); if ($z && count($z)) { $r = $z; } } $parent_id = $r[0]['id']; $parent_deleted = $r[0]['deleted']; $allow_cid = $r[0]['allow_cid']; $allow_gid = $r[0]['allow_gid']; $deny_cid = $r[0]['deny_cid']; $deny_gid = $r[0]['deny_gid']; $arr['wall'] = $r[0]['wall']; $notify_type = 'comment-new'; // if the parent is private, force privacy for the entire conversation // This differs from the above settings as it subtly allows comments from // email correspondents to be private even if the overall thread is not. if ($r[0]['private']) { $arr['private'] = $r[0]['private']; } // Edge case. We host a public forum that was originally posted to privately. // The original author commented, but as this is a comment, the permissions // weren't fixed up so it will still show the comment as private unless we fix it here. if (intval($r[0]['forum_mode']) == 1 && !$r[0]['private']) { $arr['private'] = 0; } // If its a post from myself then tag the thread as "mention" logger("item_store: Checking if parent " . $parent_id . " has to be tagged as mention for user " . $arr['uid'], LOGGER_DEBUG); $u = q("select * from user where uid = %d limit 1", intval($arr['uid'])); if (count($u)) { $a = get_app(); $self = normalise_link($a->get_baseurl() . '/profile/' . $u[0]['nickname']); logger("item_store: 'myself' is " . $self . " for parent " . $parent_id . " checking against " . $arr['author-link'] . " and " . $arr['owner-link'], LOGGER_DEBUG); if (normalise_link($arr['author-link']) == $self or normalise_link($arr['owner-link']) == $self) { q("UPDATE `thread` SET `mention` = 1 WHERE `iid` = %d", intval($parent_id)); logger("item_store: tagged thread " . $parent_id . " as mention for user " . $self, LOGGER_DEBUG); } } } else { // Allow one to see reply tweets from status.net even when // we don't have or can't see the original post. if ($force_parent) { logger('item_store: $force_parent=true, reply converted to top-level post.'); $parent_id = 0; $arr['parent-uri'] = $arr['uri']; $arr['gravity'] = 0; } else { logger('item_store: item parent was not found - ignoring item'); return 0; } $parent_deleted = 0; } } $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($arr['uri']), intval($arr['uid'])); if ($r && count($r)) { logger('item-store: duplicate item ignored. ' . print_r($arr, true)); return 0; } call_hooks('post_remote', $arr); if (x($arr, 'cancel')) { logger('item_store: post cancelled by plugin.'); return 0; } dbesc_array($arr); logger('item_store: ' . print_r($arr, true), LOGGER_DATA); $r = dbq("INSERT INTO `item` (`" . implode("`, `", array_keys($arr)) . "`) VALUES ('" . implode("', '", array_values($arr)) . "')"); // find the item we just created $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d ORDER BY `id` ASC ", $arr['uri'], intval($arr['uid'])); if (count($r)) { $current_post = $r[0]['id']; logger('item_store: created item ' . $current_post); // Only check for notifications on start posts if ($arr['parent-uri'] === $arr['uri']) { add_thread($r[0]['id']); logger('item_store: Check notification for contact ' . $arr['contact-id'] . ' and post ' . $current_post, LOGGER_DEBUG); // Send a notification for every new post? $r = q("SELECT `notify_new_posts` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `notify_new_posts` LIMIT 1", intval($arr['contact-id']), intval($arr['uid'])); if (count($r)) { logger('item_store: Send notification for contact ' . $arr['contact-id'] . ' and post ' . $current_post, LOGGER_DEBUG); $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1", intval($arr['uid'])); $item = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d", intval($current_post), intval($arr['uid'])); $a = get_app(); require_once 'include/enotify.php'; notification(array('type' => NOTIFY_SHARE, 'notify_flags' => $u[0]['notify-flags'], 'language' => $u[0]['language'], 'to_name' => $u[0]['username'], 'to_email' => $u[0]['email'], 'uid' => $u[0]['uid'], 'item' => $item[0], 'link' => $a->get_baseurl() . '/display/' . urlencode($arr['guid']), 'source_name' => $item[0]['author-name'], 'source_link' => $item[0]['author-link'], 'source_photo' => $item[0]['author-avatar'], 'verb' => ACTIVITY_TAG, 'otype' => 'item')); logger('item_store: Notification sent for contact ' . $arr['contact-id'] . ' and post ' . $current_post, LOGGER_DEBUG); } } } else { logger('item_store: could not locate created item'); return 0; } if (count($r) > 1) { logger('item_store: duplicated post occurred. Removing duplicates.'); q("DELETE FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `id` != %d ", $arr['uri'], intval($arr['uid']), intval($current_post)); } if (!$parent_id || $arr['parent-uri'] === $arr['uri']) { $parent_id = $current_post; } if (strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid)) { $private = 1; } else { $private = $arr['private']; } // Set parent id - and also make sure to inherit the parent's ACLs. $r = q("UPDATE `item` SET `parent` = %d, `allow_cid` = '%s', `allow_gid` = '%s',\n\t\t`deny_cid` = '%s', `deny_gid` = '%s', `private` = %d, `deleted` = %d WHERE `id` = %d", intval($parent_id), dbesc($allow_cid), dbesc($allow_gid), dbesc($deny_cid), dbesc($deny_gid), intval($private), intval($parent_deleted), intval($current_post)); // Complete ostatus threads if ($ostatus_conversation) { complete_conversation($current_post, $ostatus_conversation); } $arr['id'] = $current_post; $arr['parent'] = $parent_id; $arr['allow_cid'] = $allow_cid; $arr['allow_gid'] = $allow_gid; $arr['deny_cid'] = $deny_cid; $arr['deny_gid'] = $deny_gid; $arr['private'] = $private; $arr['deleted'] = $parent_deleted; // update the commented timestamp on the parent q("UPDATE `item` set `commented` = '%s', `changed` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), dbesc(datetime_convert()), intval($parent_id)); update_thread($parent_id); if ($dsprsig) { q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", intval($current_post), dbesc($dsprsig->signed_text), dbesc($dsprsig->signature), dbesc($dsprsig->signer)); } /** * If this is now the last-child, force all _other_ children of this parent to *not* be last-child */ if ($arr['last-child']) { $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d AND `id` != %d", dbesc($arr['uri']), intval($arr['uid']), intval($current_post)); } $deleted = tag_deliver($arr['uid'], $current_post); // current post can be deleted if is for a communuty page and no mention are // in it. if (!$deleted) { // Store the fresh generated item into the cache $cachefile = get_cachefile($arr["guid"] . "-" . hash("md5", $arr['body'])); if ($cachefile != '' and !file_exists($cachefile)) { $s = prepare_text($arr['body']); $a = get_app(); $stamp1 = microtime(true); file_put_contents($cachefile, $s); $a->save_timestamp($stamp1, "file"); logger('item_store: put item ' . $current_post . ' into cachefile ' . $cachefile); } $r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post)); if (count($r) == 1) { call_hooks('post_remote_end', $r[0]); } else { logger('item_store: new item not found in DB, id ' . $current_post); } } create_tags_from_item($current_post); create_files_from_item($current_post); if ($notify) { proc_run('php', "include/notifier.php", $notify_type, $current_post); } return $current_post; }
function put_item_in_cache(&$item, $update = false) { if ($item["rendered-hash"] != hash("md5", $item["body"]) or $item["rendered-hash"] == "" or $item["rendered-html"] == "" or get_config("system", "ignore_cache")) { // The function "redir_private_images" changes the body. // I'm not sure if we should store it permanently, so we save the old value. $body = $item["body"]; $a = get_app(); redir_private_images($a, $item); $item["rendered-html"] = prepare_text($item["body"]); $item["rendered-hash"] = hash("md5", $item["body"]); $item["body"] = $body; if ($update and $item["id"] != 0) { q("UPDATE `item` SET `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d", dbesc($item["rendered-html"]), dbesc($item["rendered-hash"]), intval($item["id"])); } } }
function prepare_body(&$item, $attach = false) { call_hooks('prepare_body_init', $item); $s = ''; $photo = ''; $is_photo = $item['verb'] === ACTIVITY_POST && $item['obj_type'] === ACTIVITY_OBJ_PHOTO ? true : false; if ($is_photo) { $object = json_decode($item['obj'], true); // if original photo width is <= 640px prepend it to item body if ($object['link'][0]['width'] && $object['link'][0]['width'] <= 640) { $s .= '<div class="inline-photo-item-wrapper"><a href="' . zid(rawurldecode($object['id'])) . '" target="_blank"><img class="inline-photo-item" style="max-width:' . $object['link'][0]['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($object['link'][0]['href'])) . '"></a></div>' . $s; } // if original photo width is > 640px make it a cover photo if ($object['link'][0]['width'] && $object['link'][0]['width'] > 640) { $scale = $object['link'][1]['width'] == 1024 || $object['link'][1]['height'] == 1024 ? 1 : 0; $photo = '<a href="' . zid(rawurldecode($object['id'])) . '" target="_blank"><img style="max-width:' . $object['link'][$scale]['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($object['link'][$scale]['href'])) . '"></a>'; } } $s .= prepare_text($item['body'], $item['mimetype'], false); $event = $item['obj_type'] === ACTIVITY_OBJ_EVENT ? format_event_obj($item['obj']) : false; $prep_arr = array('item' => $item, 'html' => $event ? $event['content'] : $s, 'event' => $event['header'], 'photo' => $photo); call_hooks('prepare_body', $prep_arr); $s = $prep_arr['html']; $photo = $prep_arr['photo']; $event = $prep_arr['event']; // q("update item set html = '%s' where id = %d", // dbesc($s), // intval($item['id']) // ); if (!$attach) { return $s; } if (strpos($s, '<div class="map">') !== false && $item['coord']) { $x = generate_map(trim($item['coord'])); if ($x) { $s = preg_replace('/\\<div class\\=\\"map\\"\\>/', '$0' . $x, $s); } } $attachments = theme_attachments($item); $writeable = get_observer_hash() == $item['owner_xchan'] ? true : false; $tags = format_hashtags($item); if ($item['resource_type']) { $mentions = format_mentions($item); } $categories = format_categories($item, $writeable); if (local_channel() == $item['uid']) { $filer = format_filer($item); } $s = sslify($s); $prep_arr = array('item' => $item, 'photo' => $photo, 'html' => $s, 'event' => $event, 'categories' => $categories, 'folders' => $filer, 'tags' => $tags, 'mentions' => $mentions, 'attachments' => $attachments); call_hooks('prepare_body_final', $prep_arr); unset($prep_arr['item']); return $prep_arr; }
function widget_random_block($arr) { $channel_id = 0; if (array_key_exists('channel_id', $arr) && intval($arr['channel_id'])) { $channel_id = intval($arr['channel_id']); } if (!$channel_id) { $channel_id = get_app()->profile_uid; } if (!$channel_id) { return ''; } if (array_key_exists('contains', $arr)) { $contains = $arr['contains']; } $o = ''; require_once 'include/security.php'; $sql_options = item_permissions_sql($channel_id); $randfunc = db_getfunc('RAND'); $r = q("select item.* from item left join item_id on item.id = item_id.iid\n\t\twhere item.uid = %d and sid like '%s' and service = 'BUILDBLOCK' and \n\t\titem_type = %d {$sql_options} order by {$randfunc} limit 1", intval($channel_id), dbesc('%' . $contains . '%'), intval(ITEM_TYPE_BLOCK)); if ($r) { $o = '<div class="widget bblock">'; if ($r[0]['title']) { $o .= '<h3>' . $r[0]['title'] . '</h3>'; } $o .= prepare_text($r[0]['body'], $r[0]['mimetype']); $o .= '</div>'; } return $o; }
function block($s, $class = '') { $var = array(); $matches = array(); $name = $s; $class = $class ? $class : 'bblock widget'; $cnt = preg_match_all("/\\[var=(.*?)\\](.*?)\\[\\/var\\]/ism", $s, $matches, PREG_SET_ORDER); if ($cnt) { foreach ($matches as $mtch) { $var[$mtch[1]] = $mtch[2]; $name = str_replace($mtch[0], '', $name); } } $o = ''; $channel_id = $this->get_channel_id(); if ($channel_id) { $r = q("select * from item inner join item_id on iid = item.id and item_id.uid = item.uid and item.uid = %d and service = 'BUILDBLOCK' and sid = '%s' limit 1", intval($channel_id), dbesc($name)); if ($r) { //check for eventual menus in the block and parse them $cnt = preg_match_all("/\\[menu\\](.*?)\\[\\/menu\\]/ism", $r[0]['body'], $matches, PREG_SET_ORDER); if ($cnt) { foreach ($matches as $mtch) { $r[0]['body'] = str_replace($mtch[0], $this->menu(trim($mtch[1])), $r[0]['body']); } } $cnt = preg_match_all("/\\[menu=(.*?)\\](.*?)\\[\\/menu\\]/ism", $r[0]['body'], $matches, PREG_SET_ORDER); if ($cnt) { foreach ($matches as $mtch) { $r[0]['body'] = str_replace($mtch[0], $this->menu(trim($mtch[2]), $mtch[1]), $r[0]['body']); } } //emit the block $o .= $var['wrap'] == 'none' ? '' : '<div class="' . $class . '">'; if ($r[0]['title'] && trim($r[0]['body']) != '$content') { $o .= '<h3>' . $r[0]['title'] . '</h3>'; } if (trim($r[0]['body']) === '$content') { $o .= \App::$page['content']; } else { $o .= prepare_text($r[0]['body'], $r[0]['mimetype']); } $o .= $var['wrap'] == 'none' ? '' : '</div>'; } } return $o; }
function showRegistrationForm($id, $aname, $rid, $letter_template, $error_message, $successful_message, $email_error_message) { global $module_filepath, $auth, $DB, $Q, $REQUEST_URI, $module_name, $pt_l, $pt_action, $AllowToSend, $AllowToSendText, $HTTP_HOST; $filename = $module_filepath . "/_t/_items/" . $letter_template . ".tpl"; if (file_exists($filename)) { $f = file($filename); $letter_template = join("", $f); } else { return "File " . $letter_template . ".tpl not found."; } $query = "select * from " . $module_name . " where id=" . $id; $Q->query($DB, $query); $info = $Q->getrow(); $text = prepare_text($info); $lang = $info[lang]; if ($AllowToSend) { // echo $AllowToSendText; $email = strip_tags($AllowToSendText); $email = ereg_replace("mail", "", $email); $email = trim(ereg_replace("^[^]+", "", $email)); $email = trim(ereg_replace("^[^a-zA-Z0-9]+", "", $email)); $email = ereg_replace("(^[a-zA-Z0-9\\-\\.@_]+)[^a-zA-Z0-9\\-\\.@_]+.*", "\\1", $email); // echo $email; if (!is_email($email)) { return "<font color=#FF0000>" . $email_error_message . "</font>"; } $query = "select * from " . $module_name . " where rid=" . $rid . " and name='" . $email . "'"; $Q->query($DB, $query); $count = $Q->numrows(); //echo $query; if ($count) { $text = "<font color=#FF0000>" . $error_message . "</font>"; } else { $r = getmaxid("id", $module_name); $ddate = convdate(date("d-m-Y H:i:s", time())); $password = substr(strtoupper(md5(rand())), 1, 5); $query = "INSERT INTO " . $module_name . " VALUES({$r}," . $rid . ",'','" . $aname . "','" . $lang . "','" . $ddate . "','" . $email . "','" . $password . "','" . $AllowToSendText . "','','','','','','','','','','','')"; $Q->query($DB, $query); // echo $query; $text = $successful_message; $sitename = ereg_replace("www\\.", "", $HTTP_HOST); $letter_template = ereg_replace("\\[name\\]", $email, $letter_template); $letter_template = ereg_replace("\\[anons\\]", $password, $letter_template); // echo $letter_template; mail($email, $sitename, "Content-Type:text/html;\nContent-Transfer-Encoding: 8bit\n\n" . $letter_template . "\n\n", "Content-Type:multipart/mixed; charset=Windows-1251;"); } } return $text; }
/** * Given an item array, convert the body element from bbcode to html and add smilie icons. * If attach is true, also add icons for item attachments * * @param array $item * @param boolean $attach * @return string item body html * @hook prepare_body_init item array before any work * @hook prepare_body ('item'=>item array, 'html'=>body string) after first bbcode to html * @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author) */ function prepare_body(&$item, $attach = false, $preview = false) { $a = get_app(); call_hooks('prepare_body_init', $item); $searchpath = $a->get_baseurl() . "/search?tag="; $tags = array(); $hashtags = array(); $mentions = array(); if (!get_config('system', 'suppress_tags')) { $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`", intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); foreach ($taglist as $tag) { if ($tag["url"] == "") { $tag["url"] = $searchpath . strtolower($tag["term"]); } if ($tag["type"] == TERM_HASHTAG) { $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>"; $prefix = "#"; } elseif ($tag["type"] == TERM_MENTION) { $mentions[] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>"; $prefix = "@"; } $tags[] = $prefix . "<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>"; } } $item['tags'] = $tags; $item['hashtags'] = $hashtags; $item['mentions'] = $mentions; //$cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body'])); $cachefile = get_cachefile($item["guid"] . "-" . hash("md5", $item['body'])); if ($cachefile != '') { if (file_exists($cachefile)) { $stamp1 = microtime(true); $s = file_get_contents($cachefile); $a->save_timestamp($stamp1, "file"); } else { redir_private_images($a, $item); $s = prepare_text($item['body']); $stamp1 = microtime(true); file_put_contents($cachefile, $s); $a->save_timestamp($stamp1, "file"); logger('prepare_body: put item ' . $item["id"] . ' into cachefile ' . $cachefile); } } else { redir_private_images($a, $item); $s = prepare_text($item['body']); } require_once "mod/proxy.php"; $s = proxy_parse_html($s); $prep_arr = array('item' => $item, 'html' => $s, 'preview' => $preview); call_hooks('prepare_body', $prep_arr); $s = $prep_arr['html']; if (!$attach) { // Replace the blockquotes with quotes that are used in mails $mailquote = '<blockquote type="cite" class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">'; $s = str_replace(array('<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'), array($mailquote, $mailquote, $mailquote), $s); return $s; } $as = ''; $vhead = false; $arr = explode('[/attach],', $item['attach']); if (count($arr)) { $as .= '<div class="body-attach">'; foreach ($arr as $r) { $matches = false; $icon = ''; $cnt = preg_match_all('|\\[attach\\]href=\\"(.*?)\\" length=\\"(.*?)\\" type=\\"(.*?)\\" title=\\"(.*?)\\"|', $r, $matches, PREG_SET_ORDER); if ($cnt) { foreach ($matches as $mtch) { $mime = $mtch[3]; if (local_user() == $item['uid'] && $item['contact-id'] != $a->contact['id'] && $item['network'] == NETWORK_DFRN) { $the_url = $a->get_baseurl() . '/redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1]; } else { $the_url = $mtch[1]; } if (strpos($mime, 'video') !== false) { if (!$vhead) { $vhead = true; $a->page['htmlhead'] .= replace_macros(get_markup_template('videos_head.tpl'), array('$baseurl' => $a->get_baseurl())); $a->page['end'] .= replace_macros(get_markup_template('videos_end.tpl'), array('$baseurl' => $a->get_baseurl())); } $id = end(explode('/', $the_url)); $as .= replace_macros(get_markup_template('video_top.tpl'), array('$video' => array('id' => $id, 'title' => t('View Video'), 'src' => $the_url, 'mime' => $mime))); } $filetype = strtolower(substr($mime, 0, strpos($mime, '/'))); if ($filetype) { $filesubtype = strtolower(substr($mime, strpos($mime, '/') + 1)); $filesubtype = str_replace('.', '-', $filesubtype); } else { $filetype = 'unkn'; $filesubtype = 'unkn'; } $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>'; /*$icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/'))); switch($icontype) { case 'video': case 'audio': case 'image': case 'text': $icon = '<div class="attachtype icon s22 type-' . $icontype . '"></div>'; break; default: $icon = '<div class="attachtype icon s22 type-unkn"></div>'; break; }*/ $title = strlen(trim($mtch[4])) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1]); $title .= ' ' . $mtch[2] . ' ' . t('bytes'); $as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" >' . $icon . '</a>'; } } } $as .= '<div class="clear"></div></div>'; } $s = $s . $as; // Look for spoiler $spoilersearch = '<blockquote class="spoiler">'; // Remove line breaks before the spoiler while (strpos($s, "\n" . $spoilersearch) !== false) { $s = str_replace("\n" . $spoilersearch, $spoilersearch, $s); } while (strpos($s, "<br />" . $spoilersearch) !== false) { $s = str_replace("<br />" . $spoilersearch, $spoilersearch, $s); } while (strpos($s, $spoilersearch) !== false) { $pos = strpos($s, $spoilersearch); $rnd = random_string(8); $spoilerreplace = '<br /> <span id="spoiler-wrap-' . $rnd . '" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'spoiler-' . $rnd . '\');">' . sprintf(t('Click to open/close')) . '</span>' . '<blockquote class="spoiler" id="spoiler-' . $rnd . '" style="display: none;">'; $s = substr($s, 0, $pos) . $spoilerreplace . substr($s, $pos + strlen($spoilersearch)); } // Look for quote with author $authorsearch = '<blockquote class="author">'; while (strpos($s, $authorsearch) !== false) { $pos = strpos($s, $authorsearch); $rnd = random_string(8); $authorreplace = '<br /> <span id="author-wrap-' . $rnd . '" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'author-' . $rnd . '\');">' . sprintf(t('Click to open/close')) . '</span>' . '<blockquote class="author" id="author-' . $rnd . '" style="display: block;">'; $s = substr($s, 0, $pos) . $authorreplace . substr($s, $pos + strlen($authorsearch)); } // replace friendica image url size with theme preference if (x($a->theme_info, 'item_image_size')) { $ps = $a->theme_info['item_image_size']; $s = preg_replace('|(<img[^>]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "\$1-" . $ps, $s); } $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body_final', $prep_arr); return $prep_arr['html']; }
<?php $query = "select * from " . $module_name . " where id='" . $formid . "'"; $Q->query($DB, $query); $count = $Q->numrows(); if ($count == 0) { exit; } $row = $Q->getrow(); $ordertext = ereg_replace("<", "<", $ordertext); $ordertext = ereg_replace(">", ">", $ordertext); //echo $ordertext; //$ordertext=ereg_replace("\<a[^;]+\>[^\&]+<\/a>","",$ordertext); //echo $ordertext; $row[text] = "<input type=hidden value='" . $ordertext . "'><p>" . $row[text]; $p = prepare_text($row); echo $p;
function photos_content(&$a) { // URLs: // photos/name // photos/name/album/xxxxx (xxxxx is album name) // photos/name/image/xxxxx if (get_config('system', 'block_public') && !local_channel() && !remote_channel()) { notice(t('Public access denied.') . EOL); return; } $unsafe = array_key_exists('unsafe', $_REQUEST) && $_REQUEST['unsafe'] ? 1 : 0; require_once 'include/bbcode.php'; require_once 'include/security.php'; require_once 'include/conversation.php'; if (!x($a->data, 'channel')) { notice(t('No photos selected') . EOL); return; } $ph = photo_factory(''); $phototypes = $ph->supportedTypes(); $_SESSION['photo_return'] = $a->cmd; // // Parse arguments // $can_comment = perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'post_comments'); if (argc() > 3) { $datatype = argv(2); $datum = argv(3); } else { if (argc() > 2) { $datatype = argv(2); $datum = ''; } else { $datatype = 'summary'; } } if (argc() > 4) { $cmd = argv(4); } else { $cmd = 'view'; } // // Setup permissions structures // $can_post = false; $visitor = 0; $owner_uid = $a->data['channel']['channel_id']; $owner_aid = $a->data['channel']['channel_account_id']; $observer = $a->get_observer(); $can_post = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'write_storage'); $can_view = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'view_storage'); if (!$can_view) { notice(t('Access to this item is restricted.') . EOL); return; } $sql_extra = permissions_sql($owner_uid); $o = ""; $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; // tabs $_is_owner = local_channel() && local_channel() == $owner_uid; $o .= profile_tabs($a, $_is_owner, $a->data['channel']['channel_address']); /** * Display upload form */ if ($can_post) { $uploader = ''; $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'], 'addon_text' => $uploader, 'default_upload' => true); call_hooks('photo_upload_form', $ret); /* Show space usage */ $r = q("select sum(size) as total from photo where aid = %d and scale = 0 ", intval($a->data['channel']['channel_account_id'])); $limit = service_class_fetch($a->data['channel']['channel_id'], 'photo_upload_limit'); if ($limit !== false) { $usage_message = sprintf(t("%1\$.2f MB of %2\$.2f MB photo storage used."), $r[0]['total'] / 1024000, $limit / 1024000); } else { $usage_message = sprintf(t('%1$.2f MB photo storage used.'), $r[0]['total'] / 1024000); } if ($_is_owner) { $channel = $a->get_channel(); $acl = new AccessList($channel); $channel_acl = $acl->get(); $lockstate = $acl->is_private() ? 'lock' : 'unlock'; } $aclselect = $_is_owner ? populate_acl($channel_acl, false) : ''; $selname = $datum ? hex2bin($datum) : ''; $albums = array_key_exists('albums', $a->data) ? $a->data['albums'] : photos_albums_list($a->data['channel'], $a->data['observer']); if (!$selname) { $def_album = get_pconfig($a->data['channel']['channel_id'], 'system', 'photo_path'); if ($def_album) { $selname = filepath_macro($def_album); $albums['album'][] = array('text' => $selname); } } $tpl = get_markup_template('photos_upload.tpl'); $upload_form = replace_macros($tpl, array('$pagename' => t('Upload Photos'), '$sessid' => session_id(), '$usage' => $usage_message, '$nickname' => $a->data['channel']['channel_address'], '$newalbum_label' => t('Enter an album name'), '$newalbum_placeholder' => t('or select an existing album (doubleclick)'), '$visible' => array('visible', t('Create a status post for this upload'), 0, '', array(t('No'), t('Yes'))), '$albums' => $albums['albums'], '$selname' => $selname, '$permissions' => t('Permissions'), '$aclselect' => $aclselect, '$lockstate' => $lockstate, '$uploader' => $ret['addon_text'], '$default' => $ret['default_upload'] ? true : false, '$uploadurl' => $ret['post_url'], '$submit' => t('Submit'))); } // // dispatch request // /* * Display a single photo album */ if ($datatype === 'album') { if (strlen($datum)) { if (strlen($datum) & 1 || !ctype_xdigit($datum)) { notice(t('Album name could not be decoded') . EOL); logger('mod_photos: illegal album encoding: ' . $datum); $datum = ''; } } $album = $datum ? hex2bin($datum) : ''; $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 and photo_usage IN ( %d, %d ) and is_nsfw = %d {$sql_extra} GROUP BY `resource_id`", intval($owner_uid), dbesc($album), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe)); if (count($r)) { $a->set_pager_total(count($r)); $a->set_pager_itemspage(60); } else { goaway($a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address']); } if ($_GET['order'] === 'posted') { $order = 'ASC'; } else { $order = 'DESC'; } $r = q("SELECT p.resource_id, p.id, p.filename, p.type, p.scale, p.description, p.created FROM photo p INNER JOIN\n\t\t\t\t(SELECT resource_id, max(scale) scale FROM photo WHERE uid = %d AND album = '%s' AND scale <= 4 AND photo_usage IN ( %d, %d ) and is_nsfw = %d {$sql_extra} GROUP BY resource_id) ph \n\t\t\t\tON (p.resource_id = ph.resource_id AND p.scale = ph.scale)\n\t\t\tORDER BY created {$order} LIMIT %d OFFSET %d", intval($owner_uid), dbesc($album), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe), intval($a->pager['itemspage']), intval($a->pager['start'])); //edit album name $album_edit = null; if ($album !== t('Profile Photos') && $album !== 'Profile Photos' && $album !== 'Contact Photos' && $album !== t('Contact Photos')) { if ($can_post) { if ($a->get_template_engine() === 'internal') { $album_e = template_escape($album); } else { $album_e = $album; } $albums = array_key_exists('albums', $a->data) ? $a->data['albums'] : photos_albums_list($a->data['channel'], $a->data['observer']); // @fixme - syncronise actions with DAV // $edit_tpl = get_markup_template('album_edit.tpl'); // $album_edit = replace_macros($edit_tpl,array( // '$nametext' => t('Enter a new album name'), // '$name_placeholder' => t('or select an existing one (doubleclick)'), // '$nickname' => $a->data['channel']['channel_address'], // '$album' => $album_e, // '$albums' => $albums['albums'], // '$hexalbum' => bin2hex($album), // '$submit' => t('Submit'), // '$dropsubmit' => t('Delete Album') // )); } } if ($_GET['order'] === 'posted') { $order = array(t('Show Newest First'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($album)); } else { $order = array(t('Show Oldest First'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($album) . '?f=&order=posted'); } $photos = array(); if (count($r)) { $twist = 'rotright'; foreach ($r as $rr) { if ($twist == 'rotright') { $twist = 'rotleft'; } else { $twist = 'rotright'; } $ext = $phototypes[$rr['type']]; $imgalt_e = $rr['filename']; $desc_e = $rr['description']; $imagelink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : ''); $photos[] = array('id' => $rr['id'], 'twist' => ' ' . $twist . rand(2, 4), 'link' => $imagelink, 'title' => t('View Photo'), 'src' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . $rr['scale'] . '.' . $ext, 'alt' => $imgalt_e, 'desc' => $desc_e, 'ext' => $ext, 'hash' => $rr['resource_id'], 'unknown' => t('Unknown')); } } if ($_REQUEST['aj']) { if ($photos) { $o = replace_macros(get_markup_template('photosajax.tpl'), array('$photos' => $photos)); } else { $o = '<div id="content-complete"></div>'; } echo $o; killme(); } else { $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>"; $tpl = get_markup_template('photo_album.tpl'); $o .= replace_macros($tpl, array('$photos' => $photos, '$album' => $album, '$album_edit' => array(t('Edit Album'), $album_edit), '$can_post' => $can_post, '$upload' => array(t('Upload'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/upload/' . bin2hex($album)), '$order' => $order, '$upload_form' => $upload_form, '$usage' => $usage_message)); } if (!$photos && $_REQUEST['aj']) { $o .= '<div id="content-complete"></div>'; echo $o; killme(); } // $o .= paginate($a); return $o; } /** * Display one photo */ if ($datatype === 'image') { // fetch image, item containing image, then comments $ph = q("SELECT id,aid,uid,xchan,resource_id,created,edited,title,`description`,album,filename,`type`,height,width,`size`,scale,photo_usage,is_nsfw,allow_cid,allow_gid,deny_cid,deny_gid FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' \n\t\t\t{$sql_extra} ORDER BY `scale` ASC ", intval($owner_uid), dbesc($datum)); if (!$ph) { /* Check again - this time without specifying permissions */ $ph = q("SELECT id FROM photo WHERE uid = %d AND resource_id = '%s' LIMIT 1", intval($owner_uid), dbesc($datum)); if ($ph) { notice(t('Permission denied. Access to this item may be restricted.') . EOL); } else { notice(t('Photo not available') . EOL); } return; } $prevlink = ''; $nextlink = ''; if ($_GET['order'] === 'posted') { $order = 'ASC'; } else { $order = 'DESC'; } $prvnxt = q("SELECT `resource_id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0 \n\t\t\t{$sql_extra} ORDER BY `created` {$order} ", dbesc($ph[0]['album']), intval($owner_uid)); if (count($prvnxt)) { for ($z = 0; $z < count($prvnxt); $z++) { if ($prvnxt[$z]['resource_id'] == $ph[0]['resource_id']) { $prv = $z - 1; $nxt = $z + 1; if ($prv < 0) { $prv = count($prvnxt) - 1; } if ($nxt >= count($prvnxt)) { $nxt = 0; } break; } } $prevlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$prv]['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : ''); $nextlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$nxt]['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : ''); } if (count($ph) == 1) { $hires = $lores = $ph[0]; } if (count($ph) > 1) { if ($ph[1]['scale'] == 2) { // original is 640 or less, we can display it directly $hires = $lores = $ph[0]; } else { $hires = $ph[0]; $lores = $ph[1]; } } $album_link = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($ph[0]['album']); $tools = Null; $lock = Null; if ($can_post && $ph[0]['uid'] == $owner_uid) { $tools = array('profile' => array($a->get_baseurl() . '/profile_photo/use/' . $ph[0]['resource_id'], t('Use as profile photo'))); } // lockstate $lockstate = strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']) ? array('lock', t('Private Photo')) : array('unlock', Null); $a->page['htmlhead'] .= '<script>$(document).keydown(function(event) {' . "\n"; if ($prevlink) { $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = \'' . $prevlink . '\'; }' . "\n"; } if ($nextlink) { $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = \'' . $nextlink . '\'; }' . "\n"; } $a->page['htmlhead'] .= '});</script>'; if ($prevlink) { $prevlink = array($prevlink, t('Previous')); } $photo = array('href' => $a->get_baseurl() . '/photo/' . $hires['resource_id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']], 'title' => t('View Full Size'), 'src' => $a->get_baseurl() . '/photo/' . $lores['resource_id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('', '', '', 'ymdhis')); if ($nextlink) { $nextlink = array($nextlink, t('Next')); } // Do we have an item for this photo? $linked_items = q("SELECT * FROM item WHERE resource_id = '%s' and resource_type = 'photo' \n\t\t\t{$sql_extra} LIMIT 1", dbesc($datum)); $map = null; if ($linked_items) { xchan_query($linked_items); $linked_items = fetch_post_tags($linked_items, true); $link_item = $linked_items[0]; $item_normal = item_normal(); $r = q("select * from item where parent_mid = '%s' \n\t\t\t\t{$item_normal} and uid = %d {$sql_extra} ", dbesc($link_item['mid']), intval($link_item['uid'])); if ($r) { xchan_query($r); $r = fetch_post_tags($r, true); $r = conv_sort($r, 'commented'); } $tags = array(); if ($link_item['term']) { $cnt = 0; foreach ($link_item['term'] as $t) { $tags[$cnt] = array(0 => format_term_for_display($t)); if ($can_post && $ph[0]['uid'] == $owner_uid) { $tags[$cnt][1] = 'tagrm/drop/' . $link_item['id'] . '/' . bin2hex($t['term']); //?f=&item=' . $link_item['id']; $tags[$cnt][2] = t('Remove'); } $cnt++; } } if (local_channel() && local_channel() == $link_item['uid']) { q("UPDATE `item` SET item_unseen = 0 WHERE parent = %d and uid = %d and item_unseen = 1", intval($link_item['parent']), intval(local_channel())); } if ($link_item['coord']) { $map = generate_map($link_item['coord']); } } // logger('mod_photo: link_item' . print_r($link_item,true)); // FIXME - remove this when we move to conversation module $r = $r[0]['children']; $edit = null; if ($can_post) { $album_e = $ph[0]['album']; $caption_e = $ph[0]['description']; $aclselect_e = $_is_owner ? populate_acl($ph[0]) : ''; $albums = array_key_exists('albums', $a->data) ? $a->data['albums'] : photos_albums_list($a->data['channel'], $a->data['observer']); $_SESSION['album_return'] = bin2hex($ph[0]['album']); $edit = array('edit' => t('Edit photo'), 'id' => $link_item['id'], 'rotatecw' => t('Rotate CW (right)'), 'rotateccw' => t('Rotate CCW (left)'), 'albums' => $albums['albums'], 'album' => $album_e, 'newalbum_label' => t('Enter a new album name'), 'newalbum_placeholder' => t('or select an existing one (doubleclick)'), 'nickname' => $a->data['channel']['channel_address'], 'resource_id' => $ph[0]['resource_id'], 'capt_label' => t('Caption'), 'caption' => $caption_e, 'tag_label' => t('Add a Tag'), 'permissions' => t('Permissions'), 'aclselect' => $aclselect_e, 'lockstate' => $lockstate[0], 'help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com'), 'item_id' => count($linked_items) ? $link_item['id'] : 0, 'adult_enabled' => feature_enabled($owner_uid, 'adult_photo_flagging'), 'adult' => array('adult', t('Flag as adult in album view'), intval($ph[0]['is_nsfw']), ''), 'submit' => t('Submit'), 'delete' => t('Delete Photo')); } if (count($linked_items)) { $cmnt_tpl = get_markup_template('comment_item.tpl'); $tpl = get_markup_template('photo_item.tpl'); $return_url = $a->cmd; $like_tpl = get_markup_template('like_noshare.tpl'); $likebuttons = ''; if ($can_post || $can_comment) { $likebuttons = array('id' => $link_item['id'], 'likethis' => t("I like this (toggle)"), 'nolike' => t("I don't like this (toggle)"), 'share' => t('Share'), 'wait' => t('Please wait')); } $comments = ''; if (!count($r)) { if ($can_post || $can_comment) { $commentbox = replace_macros($cmnt_tpl, array('$return_path' => '', '$mode' => 'photos', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $observer['xchan_url'], '$mytitle' => t('This is you'), '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$ww' => '', '$feature_encrypt' => false)); } } $alike = array(); $dlike = array(); $like = ''; $dislike = ''; $conv_responses = array('like' => array('title' => t('Likes', 'title')), 'dislike' => array('title' => t('Dislikes', 'title')), 'agree' => array('title' => t('Agree', 'title')), 'disagree' => array('title' => t('Disagree', 'title')), 'abstain' => array('title' => t('Abstain', 'title')), 'attendyes' => array('title' => t('Attending', 'title')), 'attendno' => array('title' => t('Not attending', 'title')), 'attendmaybe' => array('title' => t('Might attend', 'title'))); if ($r) { foreach ($r as $item) { builtin_activity_puller($item, $conv_responses); } $like_count = x($alike, $link_item['mid']) ? $alike[$link_item['mid']] : ''; $like_list = x($alike, $link_item['mid']) ? $alike[$link_item['mid'] . '-l'] : ''; if (count($like_list) > MAX_LIKERS) { $like_list_part = array_slice($like_list, 0, MAX_LIKERS); array_push($like_list_part, '<a href="#" data-toggle="modal" data-target="#likeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>'); } else { $like_list_part = ''; } $like_button_label = tt('Like', 'Likes', $like_count, 'noun'); //if (feature_enabled($conv->get_profile_owner(),'dislike')) { $dislike_count = x($dlike, $link_item['mid']) ? $dlike[$link_item['mid']] : ''; $dislike_list = x($dlike, $link_item['mid']) ? $dlike[$link_item['mid'] . '-l'] : ''; $dislike_button_label = tt('Dislike', 'Dislikes', $dislike_count, 'noun'); if (count($dislike_list) > MAX_LIKERS) { $dislike_list_part = array_slice($dislike_list, 0, MAX_LIKERS); array_push($dislike_list_part, '<a href="#" data-toggle="modal" data-target="#dislikeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>'); } else { $dislike_list_part = ''; } //} $like = isset($alike[$link_item['mid']]) ? format_like($alike[$link_item['mid']], $alike[$link_item['mid'] . '-l'], 'like', $link_item['mid']) : ''; $dislike = isset($dlike[$link_item['mid']]) ? format_like($dlike[$link_item['mid']], $dlike[$link_item['mid'] . '-l'], 'dislike', $link_item['mid']) : ''; // display comments foreach ($r as $item) { $comment = ''; $template = $tpl; $sparkle = ''; if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) { continue; } $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid']; $profile_url = zid($item['author']['xchan_url']); $sparkle = ''; $profile_name = $item['author']['xchan_name']; $profile_avatar = $item['author']['xchan_photo_m']; $profile_link = $profile_url; $drop = ''; if ($observer['xchan_hash'] === $item['author_xchan'] || $observer['xchan_hash'] === $item['owner_xchan']) { $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete'))); } $name_e = $profile_name; $title_e = $item['title']; unobscure($item); $body_e = prepare_text($item['body'], $item['mimetype']); $comments .= replace_macros($template, array('$id' => $item['id'], '$mode' => 'photos', '$profile_url' => $profile_link, '$name' => $name_e, '$thumb' => $profile_avatar, '$sparkle' => $sparkle, '$title' => $title_e, '$body' => $body_e, '$ago' => relative_date($item['created']), '$indent' => $item['parent'] != $item['id'] ? ' comment' : '', '$drop' => $drop, '$comment' => $comment)); } if ($can_post || $can_comment) { $commentbox = replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $observer['xchan_url'], '$mytitle' => t('This is you'), '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$ww' => '')); } } $paginate = paginate($a); } $album_e = array($album_link, $ph[0]['album']); $like_e = $like; $dislike_e = $dislike; $response_verbs = array('like'); if (feature_enabled($owner_uid, 'dislike')) { $response_verbs[] = 'dislike'; } $responses = get_responses($conv_responses, $response_verbs, '', $link_item); $photo_tpl = get_markup_template('photo_view.tpl'); $o .= replace_macros($photo_tpl, array('$id' => $ph[0]['id'], '$album' => $album_e, '$tools' => $tools, '$lock' => $lockstate[1], '$photo' => $photo, '$prevlink' => $prevlink, '$nextlink' => $nextlink, '$desc' => $ph[0]['description'], '$filename' => $ph[0]['filename'], '$unknown' => t('Unknown'), '$tag_hdr' => t('In This Photo:'), '$tags' => $tags, 'responses' => $responses, '$edit' => $edit, '$map' => $map, '$map_text' => t('Map'), '$likebuttons' => $likebuttons, '$like' => $like_e, '$dislike' => $dislike_e, '$like_count' => $like_count, '$like_list' => $like_list, '$like_list_part' => $like_list_part, '$like_button_label' => $like_button_label, '$like_modal_title' => t('Likes', 'noun'), '$dislike_modal_title' => t('Dislikes', 'noun'), '$dislike_count' => $dislike_count, '$dislike_list' => $dislike_list, '$dislike_list_part' => $dislike_list_part, '$dislike_button_label' => $dislike_button_label, '$modal_dismiss' => t('Close'), '$comments' => $comments, '$commentbox' => $commentbox, '$paginate' => $paginate)); $a->data['photo_html'] = $o; return $o; } // Default - show recent photos with upload link (if applicable) //$o = ''; $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' \n\t\tand photo_usage in ( %d, %d ) and is_nsfw = %d {$sql_extra} GROUP BY `resource_id`", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe)); if (count($r)) { $a->set_pager_total(count($r)); $a->set_pager_itemspage(60); } $r = q("SELECT p.resource_id, p.id, p.filename, p.type, p.album, p.scale, p.created FROM photo p INNER JOIN \n\t\t(SELECT resource_id, max(scale) scale FROM photo \n\t\t\tWHERE uid=%d AND album != '%s' AND album != '%s' \n\t\t\tAND photo_usage IN ( %d, %d ) and is_nsfw = %d {$sql_extra} group by resource_id) ph \n\t\tON (p.resource_id = ph.resource_id and p.scale = ph.scale) ORDER by p.created DESC LIMIT %d OFFSET %d", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe), intval($a->pager['itemspage']), intval($a->pager['start'])); $photos = array(); if (count($r)) { $twist = 'rotright'; foreach ($r as $rr) { if ($twist == 'rotright') { $twist = 'rotleft'; } else { $twist = 'rotright'; } $ext = $phototypes[$rr['type']]; if ($a->get_template_engine() === 'internal') { $alt_e = template_escape($rr['filename']); $name_e = template_escape($rr['album']); } else { $alt_e = $rr['filename']; $name_e = $rr['album']; } $photos[] = array('id' => $rr['id'], 'twist' => ' ' . $twist . rand(2, 4), 'link' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'], 'title' => t('View Photo'), 'src' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . ($rr['scale'] == 6 ? 4 : $rr['scale']) . '.' . $ext, 'alt' => $alt_e, 'album' => array('link' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($rr['album']), 'name' => $name_e, 'alt' => t('View Album'))); } } if ($_REQUEST['aj']) { if ($photos) { $o = replace_macros(get_markup_template('photosajax.tpl'), array('$photos' => $photos)); } else { $o = '<div id="content-complete"></div>'; } echo $o; killme(); } else { $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>"; $tpl = get_markup_template('photos_recent.tpl'); $o .= replace_macros($tpl, array('$title' => t('Recent Photos'), '$can_post' => $can_post, '$upload' => array(t('Upload'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/upload'), '$photos' => $photos, '$upload_form' => $upload_form, '$usage' => $usage_message)); } if (!$photos && $_REQUEST['aj']) { $o .= '<div id="content-complete"></div>'; echo $o; killme(); } // paginate($a); return $o; }
function prepare_body(&$item, $attach = false) { call_hooks('prepare_body_init', $item); unobscure($item); $s = prepare_text($item['body'], $item['mimetype']); $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body', $prep_arr); $s = $prep_arr['html']; if (!$attach) { return $s; } if (strpos($s, '<div class="map">') !== false && $item['coord']) { $x = generate_map(trim($item['coord'])); if ($x) { $s = preg_replace('/\\<div class\\=\\"map\\"\\>/', '$0' . $x, $s); } } $s .= theme_attachments($item); $writeable = get_observer_hash() == $item['owner_xchan'] ? true : false; $s .= format_hashtags($item); if ($item['resource_type']) { $s .= format_mentions($item); } $s .= format_categories($item, $writeable); if (local_channel() == $item['uid']) { $s .= format_filer($item); } $s = sslify($s); // Look for spoiler $spoilersearch = '<blockquote class="spoiler">'; // Remove line breaks before the spoiler while (strpos($s, "\n" . $spoilersearch) !== false) { $s = str_replace("\n" . $spoilersearch, $spoilersearch, $s); } while (strpos($s, "<br />" . $spoilersearch) !== false) { $s = str_replace("<br />" . $spoilersearch, $spoilersearch, $s); } while (strpos($s, $spoilersearch) !== false) { $pos = strpos($s, $spoilersearch); $rnd = random_string(8); $spoilerreplace = '<br /> <span id="spoiler-wrap-' . $rnd . '" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'spoiler-' . $rnd . '\');">' . sprintf(t('Click to open/close')) . '</span>' . '<blockquote class="spoiler" id="spoiler-' . $rnd . '" style="display: none;">'; $s = substr($s, 0, $pos) . $spoilerreplace . substr($s, $pos + strlen($spoilersearch)); } // Look for quote with author $authorsearch = '<blockquote class="author">'; while (strpos($s, $authorsearch) !== false) { $pos = strpos($s, $authorsearch); $rnd = random_string(8); $authorreplace = '<br /> <span id="author-wrap-' . $rnd . '" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'author-' . $rnd . '\');">' . sprintf(t('Click to open/close')) . '</span>' . '<blockquote class="author" id="author-' . $rnd . '" style="display: block;">'; $s = substr($s, 0, $pos) . $authorreplace . substr($s, $pos + strlen($authorsearch)); } $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body_final', $prep_arr); return $prep_arr['html']; }
function advanced_profile(&$a) { require_once 'include/text.php'; if (!perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'view_profile')) { return ''; } $o = ''; $o .= '<h2>' . t('Profile') . '</h2>'; if ($a->profile['name']) { $tpl = get_markup_template('profile_advanced.tpl'); $profile = array(); $profile['fullname'] = array(t('Full Name:'), $a->profile['name']); if ($a->profile['gender']) { $profile['gender'] = array(t('Gender:'), $a->profile['gender']); } $ob_hash = get_observer_hash(); if ($ob_hash && perm_is_allowed($a->profile['profile_uid'], $ob_hash, 'post_like')) { $profile['canlike'] = true; $profile['likethis'] = t('Like this channel'); $profile['profile_guid'] = $a->profile['profile_guid']; } $likers = q("select liker, xchan.* from likes left join xchan on liker = xchan_hash where channel_id = %d and target_type = '%s' and verb = '%s'", intval($a->profile['profile_uid']), dbesc(ACTIVITY_OBJ_PROFILE), dbesc(ACTIVITY_LIKE)); $profile['likers'] = array(); $profile['like_count'] = count($likers); $profile['like_button_label'] = tt('Like', 'Likes', $profile['like_count'], 'noun'); if ($likers) { foreach ($likers as $l) { $profile['likers'][] = array('name' => $l['xchan_name'], 'url' => zid($l['xchan_url'])); } } if ($a->profile['dob'] && $a->profile['dob'] != '0000-00-00') { $val = ''; if (substr($a->profile['dob'], 5, 2) === '00' || substr($a->profile['dob'], 8, 2) === '00') { $val = substr($a->profile['dob'], 0, 4); } $year_bd_format = t('j F, Y'); $short_bd_format = t('j F'); if (!$val) { $val = intval($a->profile['dob']) ? day_translate(datetime_convert('UTC', 'UTC', $a->profile['dob'] . ' 00:00 +00:00', $year_bd_format)) : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format)); } $profile['birthday'] = array(t('Birthday:'), $val); } if ($age = age($a->profile['dob'], $a->profile['timezone'], '')) { $profile['age'] = array(t('Age:'), $age); } if ($a->profile['marital']) { $profile['marital'] = array(t('Status:'), $a->profile['marital']); } if ($a->profile['with']) { $profile['marital']['with'] = bbcode($a->profile['with']); } if (strlen($a->profile['howlong']) && $a->profile['howlong'] !== NULL_DATE) { $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s')); } if ($a->profile['sexual']) { $profile['sexual'] = array(t('Sexual Preference:'), $a->profile['sexual']); } if ($a->profile['homepage']) { $profile['homepage'] = array(t('Homepage:'), linkify($a->profile['homepage'])); } if ($a->profile['hometown']) { $profile['hometown'] = array(t('Hometown:'), linkify($a->profile['hometown'])); } if ($a->profile['keywords']) { $profile['keywords'] = array(t('Tags:'), $a->profile['keywords']); } if ($a->profile['politic']) { $profile['politic'] = array(t('Political Views:'), $a->profile['politic']); } if ($a->profile['religion']) { $profile['religion'] = array(t('Religion:'), $a->profile['religion']); } if ($txt = prepare_text($a->profile['about'])) { $profile['about'] = array(t('About:'), $txt); } if ($txt = prepare_text($a->profile['interest'])) { $profile['interest'] = array(t('Hobbies/Interests:'), $txt); } if ($txt = prepare_text($a->profile['likes'])) { $profile['likes'] = array(t('Likes:'), $txt); } if ($txt = prepare_text($a->profile['dislikes'])) { $profile['dislikes'] = array(t('Dislikes:'), $txt); } if ($txt = prepare_text($a->profile['contact'])) { $profile['contact'] = array(t('Contact information and Social Networks:'), $txt); } if ($txt = prepare_text($a->profile['channels'])) { $profile['channels'] = array(t('My other channels:'), $txt); } if ($txt = prepare_text($a->profile['music'])) { $profile['music'] = array(t('Musical interests:'), $txt); } if ($txt = prepare_text($a->profile['book'])) { $profile['book'] = array(t('Books, literature:'), $txt); } if ($txt = prepare_text($a->profile['tv'])) { $profile['tv'] = array(t('Television:'), $txt); } if ($txt = prepare_text($a->profile['film'])) { $profile['film'] = array(t('Film/dance/culture/entertainment:'), $txt); } if ($txt = prepare_text($a->profile['romance'])) { $profile['romance'] = array(t('Love/Romance:'), $txt); } if ($txt = prepare_text($a->profile['work'])) { $profile['work'] = array(t('Work/employment:'), $txt); } if ($txt = prepare_text($a->profile['education'])) { $profile['education'] = array(t('School/education:'), $txt); } if ($a->profile['extra_fields']) { foreach ($a->profile['extra_fields'] as $f) { $x = q("select * from profdef where field_name = '%s' limit 1", dbesc($f)); if ($x && ($txt = prepare_text($a->profile[$f]))) { $profile[$f] = array($x[0]['field_desc'] . ':', $txt); } } $profile['extra_fields'] = $a->profile['extra_fields']; } $things = get_things($a->profile['profile_guid'], $a->profile['profile_uid']); // logger('mod_profile: things: ' . print_r($things,true), LOGGER_DATA); return replace_macros($tpl, array('$title' => t('Profile'), '$canlike' => $profile['canlike'] ? true : false, '$likethis' => t('Like this thing'), '$profile' => $profile, '$things' => $things)); } return ''; }
function comanche_block($name) { $o = ''; $channel_id = comanche_get_channel_id(); if ($channel_id) { $r = q("select * from item inner join item_id on iid = item.id and item_id.uid = item.uid and item.uid = %d and service = 'BUILDBLOCK' and sid = '%s' limit 1", intval($channel_id), dbesc($name)); if ($r) { $o = '<div class="widget bblock">'; if ($r[0]['title']) { $o .= '<h3>' . $r[0]['title'] . '</h3>'; } $o .= prepare_text($r[0]['body'], $r[0]['mimetype']); $o .= '</div>'; } } return $o; }
function store_doc_file($s) { if (is_dir($s)) { return; } $item = array(); $sys = get_sys_channel(); $item['aid'] = 0; $item['uid'] = $sys['channel_id']; if (strpos($s, '.md')) { $mimetype = 'text/markdown'; } elseif (strpos($s, '.html')) { $mimetype = 'text/html'; } else { $mimetype = 'text/bbcode'; } require_once 'include/html2plain.php'; $item['body'] = html2plain(prepare_text(file_get_contents($s), $mimetype, true)); $item['mimetype'] = 'text/plain'; $item['plink'] = z_root() . '/' . str_replace('doc', 'help', $s); $item['owner_xchan'] = $item['author_xchan'] = $sys['channel_hash']; $item['item_type'] = ITEM_TYPE_DOC; $r = q("select item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and\n\t\tsid = '%s' and item_type = %d limit 1", dbesc($s), intval(ITEM_TYPE_DOC)); if ($r) { $item['id'] = $r[0]['id']; $item['mid'] = $item['parent_mid'] = $r[0]['mid']; $x = item_store_update($item); } else { $item['mid'] = $item['parent_mid'] = item_message_id(); $x = item_store($item); } if ($x['success']) { update_remote_id($sys, $x['item_id'], ITEM_TYPE_DOC, $s, 'docfile', 0, $item['mid']); } }
function search_content(&$a, $update = 0, $load = false) { if (get_config('system', 'block_public') || get_config('system', 'block_public_search')) { if (!local_channel() && !remote_channel()) { notice(t('Public access denied.') . EOL); return; } } if ($load) { $_SESSION['loadtime'] = datetime_convert(); } nav_set_selected('search'); require_once "include/bbcode.php"; require_once 'include/security.php'; require_once 'include/conversation.php'; require_once 'include/items.php'; $format = $_REQUEST['format'] ? $_REQUEST['format'] : ''; if ($format !== '') { $update = $load = 1; } $observer = $a->get_observer(); $observer_hash = $observer ? $observer['xchan_hash'] : ''; $o = '<div id="live-search"></div>' . "\r\n"; $o .= '<h3>' . t('Search') . '</h3>'; if (x($a->data, 'search')) { $search = trim($a->data['search']); } else { $search = x($_GET, 'search') ? trim(rawurldecode($_GET['search'])) : ''; } $tag = false; if (x($_GET, 'tag')) { $tag = true; $search = x($_GET, 'tag') ? trim(rawurldecode($_GET['tag'])) : ''; } if (!local_channel() || !feature_enabled(local_channel(), 'savedsearch')) { $o .= search($search, 'search-box', '/search', local_channel() ? true : false); } if (strpos($search, '#') === 0) { $tag = true; $search = substr($search, 1); } if (strpos($search, '@') === 0) { $search = substr($search, 1); goaway(z_root() . '/directory' . '?f=1&search=' . $search); } // look for a naked webbie if (strpos($search, '@') !== false) { goaway(z_root() . '/directory' . '?f=1&search=' . $search); } if (!$search) { return $o; } if ($tag) { $sql_extra = sprintf(" AND `item`.`id` IN (select `oid` from term where otype = %d and type = %d and term = '%s') ", intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search))); } else { $regstr = db_getfunc('REGEXP'); $sql_extra = sprintf(" AND `item`.`body` {$regstr} '%s' ", dbesc(protect_sprintf(preg_quote($search)))); } // Here is the way permissions work in the search module... // Only public posts can be shown // OR your own posts if you are a logged in member // No items will be shown if the member has a blocked profile wall. if (!$update && !$load) { // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, // because browser prefetching might change it on us. We have to deliver it with the page. $o .= '<div id="live-search"></div>' . "\r\n"; $o .= "<script> var profile_uid = " . (intval(local_channel()) ? local_channel() : -1) . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; $a->page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"), array('$baseurl' => z_root(), '$pgtype' => 'search', '$uid' => $a->profile['profile_uid'] ? $a->profile['profile_uid'] : '0', '$gid' => '0', '$cid' => '0', '$cmin' => '0', '$cmax' => '0', '$star' => '0', '$liked' => '0', '$conv' => '0', '$spam' => '0', '$fh' => '0', '$nouveau' => '0', '$wall' => '0', '$list' => x($_REQUEST, 'list') ? intval($_REQUEST['list']) : 0, '$page' => $a->pager['page'] != 1 ? $a->pager['page'] : 1, '$search' => ($tag ? urlencode('#') : '') . $search, '$order' => '', '$file' => '', '$cats' => '', '$tags' => '', '$mid' => '', '$verb' => '', '$dend' => '', '$dbegin' => '')); } $pub_sql = public_permissions_sql($observer_hash); require_once 'include/identity.php'; $sys = get_sys_channel(); if ($update && $load) { $itemspage = get_pconfig(local_channel(), 'system', 'itemspage'); $a->set_pager_itemspage(intval($itemspage) ? $itemspage : 20); $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($a->pager['itemspage']), intval($a->pager['start'])); // in case somebody turned off public access to sys channel content with permissions if (!perm_is_allowed($sys['channel_id'], $observer_hash, 'view_stream')) { $sys['xchan_hash'] .= 'disabled'; } if ($load) { $r = null; if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) { $prefix = 'distinct on (created, mid)'; $suffix = 'ORDER BY created DESC, mid'; } else { $prefix = 'distinct'; $suffix = 'group by mid ORDER BY created DESC'; } if (local_channel()) { $r = q("SELECT {$prefix} mid, item.id as item_id, item.* from item\n\t\t\t\t\tWHERE item_restrict = 0\n\t\t\t\t\tAND ((( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND item_private = 0 ) \n\t\t\t\t\tOR ( `item`.`uid` = %d )) OR item.owner_xchan = '%s' )\n\t\t\t\t\t{$sql_extra}\n\t\t\t\t\t{$suffix} {$pager_sql} ", intval(local_channel()), dbesc($sys['xchan_hash'])); } if ($r === null) { $r = q("SELECT {$prefix} mid, item.id as item_id, item.* from item\n\t\t\t\t\tWHERE item_restrict = 0\n\t\t\t\t\tAND (((( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = ''\n\t\t\t\t\tAND `item`.`deny_gid` = '' AND item_private = 0 )\n\t\t\t\t\tand owner_xchan in ( " . stream_perms_xchans($observer ? PERMS_NETWORK | PERMS_PUBLIC : PERMS_PUBLIC) . " ))\n\t\t\t\t\t\t{$pub_sql} ) OR owner_xchan = '%s')\n\t\t\t\t\t{$sql_extra} \n\t\t\t\t\t{$suffix} {$pager_sql}", dbesc($sys['xchan_hash'])); } } else { $r = array(); } } if ($r) { xchan_query($r); $items = fetch_post_tags($r, true); } else { $items = array(); } if ($format == 'json') { $result = array(); require_once 'include/conversation.php'; foreach ($items as $item) { $item['html'] = bbcode($item['body']); $x = encode_item($item); $x['html'] = prepare_text($item['body'], $item['mimetype']); $result[] = $x; } json_return_and_die(array('success' => true, 'messages' => $result)); } if ($tag) { $o .= '<h2>Items tagged with: ' . htmlspecialchars($search, ENT_COMPAT, 'UTF-8') . '</h2>'; } else { $o .= '<h2>Search results for: ' . htmlspecialchars($search, ENT_COMPAT, 'UTF-8') . '</h2>'; } $o .= conversation($a, $items, 'search', $update, 'client'); return $o; }
exit; } // Check if we have Form Data to process if (isset($_GET['go']) && $_GET['go'] == "y") { $_POST['incept'] = mktime(0, 0, 0, $_POST['incept']['month'], $_POST['incept']['day'], $_POST['incept']['year']); if ($_POST['live'] != 1) { $_POST['live'] = 0; } $fields = array("incept", "custid", "contactsid", "staffid", "notes", "price", "content", "live"); // $fields = $required; $logContent = "\n"; foreach ($fields as $name) { $dbvalues[$name] = $_POST[$name]; $logContent .= $name . ':' . $_POST[$name] . "\n"; } prepare_text($dbvalues, $input); $result = db_update("quotes", $input, $_GET['id'], 'quotesid'); $logresult = logEvent(5, $logContent); header("Location: /quotes/view?id=" . $_GET['id']); exit; } // Define elements for the HTML Header include $pagetitle = "Edit Quote"; $pagescript = array("/pub/calpop/calendar_eu.js"); $pagestyle = array("/css/calendar.css"); include "../tmpl/header.php"; $sqltext = "SELECT * FROM quotes WHERE quotesid=?"; $q = $db->select($sqltext, array($_GET['id']), 'i'); if (!empty($q)) { $r = $q[0]; } else {
function item_post(&$a) { if (!local_user() && !remote_user() && !x($_REQUEST, 'commenter')) { return; } require_once 'include/security.php'; $uid = local_user(); if (x($_REQUEST, 'dropitems')) { require_once 'include/items.php'; $arr_drop = explode(',', $_REQUEST['dropitems']); drop_items($arr_drop); $json = array('success' => 1); echo json_encode($json); killme(); } call_hooks('post_local_start', $_REQUEST); // logger('postinput ' . file_get_contents('php://input')); logger('postvars ' . print_r($_REQUEST, true), LOGGER_DATA); $api_source = x($_REQUEST, 'api_source') && $_REQUEST['api_source'] ? true : false; $message_id = x($_REQUEST, 'message_id') && $api_source ? strip_tags($_REQUEST['message_id']) : ''; $return_path = x($_REQUEST, 'return') ? $_REQUEST['return'] : ''; $preview = x($_REQUEST, 'preview') ? intval($_REQUEST['preview']) : 0; // Check for doubly-submitted posts, and reject duplicates // Note that we have to ignore previews, otherwise nothing will post // after it's been previewed if (!$preview && x($_REQUEST['post_id_random'])) { if (x($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) { logger("item post: duplicate post", LOGGER_DEBUG); item_post_return($a->get_baseurl(), $api_source, $return_path); } else { $_SESSION['post-random'] = $_REQUEST['post_id_random']; } } /** * Is this a reply to something? */ $parent = x($_REQUEST, 'parent') ? intval($_REQUEST['parent']) : 0; $parent_uri = x($_REQUEST, 'parent_uri') ? trim($_REQUEST['parent_uri']) : ''; $parent_item = null; $parent_contact = null; $thr_parent = ''; $parid = 0; $r = false; $objecttype = null; if ($parent || $parent_uri) { $objecttype = ACTIVITY_OBJ_COMMENT; if (!x($_REQUEST, 'type')) { $_REQUEST['type'] = 'net-comment'; } if ($parent) { $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", intval($parent)); } elseif ($parent_uri && local_user()) { // This is coming from an API source, and we are logged in $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($parent_uri), intval(local_user())); } // if this isn't the real parent of the conversation, find it if ($r !== false && count($r)) { $parid = $r[0]['parent']; $parent_uri = $r[0]['uri']; if ($r[0]['id'] != $r[0]['parent']) { $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1", intval($parid)); } } if ($r === false || !count($r)) { notice(t('Unable to locate original post.') . EOL); if (x($_REQUEST, 'return')) { goaway($a->get_baseurl() . "/" . $return_path); } killme(); } $parent_item = $r[0]; $parent = $r[0]['id']; // multi-level threading - preserve the info but re-parent to our single level threading //if(($parid) && ($parid != $parent)) $thr_parent = $parent_uri; if ($parent_item['contact-id'] && $uid) { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($parent_item['contact-id']), intval($uid)); if (count($r)) { $parent_contact = $r[0]; } } } if ($parent) { logger('mod_item: item_post parent=' . $parent); } $profile_uid = x($_REQUEST, 'profile_uid') ? intval($_REQUEST['profile_uid']) : 0; $post_id = x($_REQUEST, 'post_id') ? intval($_REQUEST['post_id']) : 0; $app = x($_REQUEST, 'source') ? strip_tags($_REQUEST['source']) : ''; $allow_moderated = false; // here is where we are going to check for permission to post a moderated comment. // First check that the parent exists and it is a wall item. if (x($_REQUEST, 'commenter') && (!$parent || !$parent_item['wall'])) { notice(t('Permission denied.') . EOL); if (x($_REQUEST, 'return')) { goaway($a->get_baseurl() . "/" . $return_path); } killme(); } // Now check that it is a page_type of PAGE_BLOG, and that valid personal details // have been provided, and run any anti-spam plugins // TODO if (!can_write_wall($a, $profile_uid) && !$allow_moderated) { notice(t('Permission denied.') . EOL); if (x($_REQUEST, 'return')) { goaway($a->get_baseurl() . "/" . $return_path); } killme(); } // is this an edited post? $orig_post = null; if ($post_id) { $i = q("SELECT * FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($profile_uid), intval($post_id)); if (!count($i)) { killme(); } $orig_post = $i[0]; } $user = null; $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($profile_uid)); if (count($r)) { $user = $r[0]; } if ($orig_post) { $str_group_allow = $orig_post['allow_gid']; $str_contact_allow = $orig_post['allow_cid']; $str_group_deny = $orig_post['deny_gid']; $str_contact_deny = $orig_post['deny_cid']; $location = $orig_post['location']; $coord = $orig_post['coord']; $verb = $orig_post['verb']; $objecttype = $orig_post['object-type']; $emailcc = $orig_post['emailcc']; $app = $orig_post['app']; $categories = $orig_post['file']; $title = notags(trim($_REQUEST['title'])); $body = escape_tags(trim($_REQUEST['body'])); $private = $orig_post['private']; $pubmail_enable = $orig_post['pubmail']; $network = $orig_post['network']; $guid = $orig_post['guid']; } else { // if coming from the API and no privacy settings are set, // use the user default permissions - as they won't have // been supplied via a form. if ($api_source && !array_key_exists('contact_allow', $_REQUEST) && !array_key_exists('group_allow', $_REQUEST) && !array_key_exists('contact_deny', $_REQUEST) && !array_key_exists('group_deny', $_REQUEST)) { $str_group_allow = $user['allow_gid']; $str_contact_allow = $user['allow_cid']; $str_group_deny = $user['deny_gid']; $str_contact_deny = $user['deny_cid']; } else { // use the posted permissions $str_group_allow = perms2str($_REQUEST['group_allow']); $str_contact_allow = perms2str($_REQUEST['contact_allow']); $str_group_deny = perms2str($_REQUEST['group_deny']); $str_contact_deny = perms2str($_REQUEST['contact_deny']); } $title = notags(trim($_REQUEST['title'])); $location = notags(trim($_REQUEST['location'])); $coord = notags(trim($_REQUEST['coord'])); $verb = notags(trim($_REQUEST['verb'])); $emailcc = notags(trim($_REQUEST['emailcc'])); $body = escape_tags(trim($_REQUEST['body'])); $network = notags(trim($_REQUEST['network'])); $guid = get_guid(32); $naked_body = preg_replace('/\\[(.+?)\\]/', '', $body); if (version_compare(PHP_VERSION, '5.3.0', '>=')) { $l = new Text_LanguageDetect(); //$lng = $l->detectConfidence($naked_body); //$postopts = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : ''); $lng = $l->detect($naked_body, 3); if (sizeof($lng) > 0) { $postopts = ""; foreach ($lng as $language => $score) { if ($postopts == "") { $postopts = "lang="; } else { $postopts .= ":"; } $postopts .= $language . ";" . $score; } } logger('mod_item: detect language' . print_r($lng, true) . $naked_body, LOGGER_DATA); } else { $postopts = ''; } $private = strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny) ? 1 : 0; if ($user['hidewall']) { $private = 2; } // If this is a comment, set the permissions from the parent. if ($parent_item) { $private = 0; // for non native networks use the network of the original post as network of the item if ($parent_item['network'] != NETWORK_DIASPORA and $parent_item['network'] != NETWORK_OSTATUS and $network == "") { $network = $parent_item['network']; } if ($parent_item['private'] || strlen($parent_item['allow_cid']) || strlen($parent_item['allow_gid']) || strlen($parent_item['deny_cid']) || strlen($parent_item['deny_gid'])) { $private = $parent_item['private'] ? $parent_item['private'] : 1; } $str_contact_allow = $parent_item['allow_cid']; $str_group_allow = $parent_item['allow_gid']; $str_contact_deny = $parent_item['deny_cid']; $str_group_deny = $parent_item['deny_gid']; } $pubmail_enable = x($_REQUEST, 'pubmail_enable') && intval($_REQUEST['pubmail_enable']) && !$private ? 1 : 0; // if using the API, we won't see pubmail_enable - figure out if it should be set if ($api_source && $profile_uid && $profile_uid == local_user() && !$private) { $mail_disabled = function_exists('imap_open') && !get_config('system', 'imap_disabled') ? 0 : 1; if (!$mail_disabled) { $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user())); if (count($r) && intval($r[0]['pubmail'])) { $pubmail_enabled = true; } } } if (!strlen($body)) { if ($preview) { killme(); } info(t('Empty post discarded.') . EOL); if (x($_REQUEST, 'return')) { goaway($a->get_baseurl() . "/" . $return_path); } killme(); } } if (strlen($categories)) { // get the "fileas" tags for this post $filedas = file_tag_file_to_list($categories, 'file'); } // save old and new categories, so we can determine what needs to be deleted from pconfig $categories_old = $categories; $categories = file_tag_list_to_file(trim($_REQUEST['category']), 'category'); $categories_new = $categories; if (strlen($filedas)) { // append the fileas stuff to the new categories list $categories .= file_tag_list_to_file($filedas, 'file'); } // Work around doubled linefeeds in Tinymce 3.5b2 // First figure out if it's a status post that would've been // created using tinymce. Otherwise leave it alone. /* $plaintext = (local_user() ? intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled($profile_uid,'richtext') : 0); if((! $parent) && (! $api_source) && (! $plaintext)) { $body = fix_mce_lf($body); }*/ $plaintext = local_user() ? !feature_enabled($profile_uid, 'richtext') : 0; if (!$parent && !$api_source && !$plaintext) { $body = fix_mce_lf($body); } // get contact info for poster $author = null; $self = false; $contact_id = 0; if (local_user() && local_user() == $profile_uid) { $self = true; $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($_SESSION['uid'])); } elseif (remote_user()) { if (is_array($_SESSION['remote'])) { foreach ($_SESSION['remote'] as $v) { if ($v['uid'] == $profile_uid) { $contact_id = $v['cid']; break; } } } if ($contact_id) { $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($contact_id)); } } if (count($r)) { $author = $r[0]; $contact_id = $author['id']; } // get contact info for owner if ($profile_uid == local_user()) { $contact_record = $author; } else { $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($profile_uid)); if (count($r)) { $contact_record = $r[0]; } } $post_type = notags(trim($_REQUEST['type'])); if ($post_type === 'net-comment') { if ($parent_item !== null) { if ($parent_item['wall'] == 1) { $post_type = 'wall-comment'; } else { $post_type = 'remote-comment'; } } } /** * * When a photo was uploaded into the message using the (profile wall) ajax * uploader, The permissions are initially set to disallow anybody but the * owner from seeing it. This is because the permissions may not yet have been * set for the post. If it's private, the photo permissions should be set * appropriately. But we didn't know the final permissions on the post until * now. So now we'll look for links of uploaded messages that are in the * post and set them to the same permissions as the post itself. * */ $match = null; if (!$preview && preg_match_all("/\\[img([\\=0-9x]*?)\\](.*?)\\[\\/img\\]/", $body, $match)) { $images = $match[2]; if (count($images)) { $objecttype = ACTIVITY_OBJ_IMAGE; foreach ($images as $image) { if (!stristr($image, $a->get_baseurl() . '/photo/')) { continue; } $image_uri = substr($image, strrpos($image, '/') + 1); $image_uri = substr($image_uri, 0, strpos($image_uri, '-')); if (!strlen($image_uri)) { continue; } $srch = '<' . intval($contact_id) . '>'; $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = ''\n\t\t\t\t\tAND `resource-id` = '%s' AND `uid` = %d LIMIT 1", dbesc($srch), dbesc($image_uri), intval($profile_uid)); if (!count($r)) { continue; } $r = q("UPDATE `photo` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'\n\t\t\t\t\tWHERE `resource-id` = '%s' AND `uid` = %d AND `album` = '%s' ", dbesc($str_contact_allow), dbesc($str_group_allow), dbesc($str_contact_deny), dbesc($str_group_deny), dbesc($image_uri), intval($profile_uid), dbesc(t('Wall Photos'))); } } } /** * Next link in any attachment references we find in the post. */ $match = false; if (!$preview && preg_match_all("/\\[attachment\\](.*?)\\[\\/attachment\\]/", $body, $match)) { $attaches = $match[1]; if (count($attaches)) { foreach ($attaches as $attach) { $r = q("SELECT * FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($profile_uid), intval($attach)); if (count($r)) { $r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'\n\t\t\t\t\t\tWHERE `uid` = %d AND `id` = %d", dbesc($str_contact_allow), dbesc($str_group_allow), dbesc($str_contact_deny), dbesc($str_group_deny), intval($profile_uid), intval($attach)); } } } } // embedded bookmark in post? set bookmark flag $bookmark = 0; if (preg_match_all("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", $body, $match, PREG_SET_ORDER)) { $objecttype = ACTIVITY_OBJ_BOOKMARK; $bookmark = 1; } $body = bb_translate_video($body); /** * Fold multi-line [code] sequences */ $body = preg_replace('/\\[\\/code\\]\\s*\\[code\\]/ism', "\n", $body); $body = scale_external_images($body, false); // Setting the object type if not defined before if (!$objecttype) { $objecttype = ACTIVITY_OBJ_NOTE; // Default value require_once "include/plaintext.php"; $objectdata = get_attached_data($body); if ($post["type"] == "link") { $objecttype = ACTIVITY_OBJ_BOOKMARK; } elseif ($post["type"] == "video") { $objecttype = ACTIVITY_OBJ_VIDEO; } elseif ($post["type"] == "photo") { $objecttype = ACTIVITY_OBJ_IMAGE; } } /** * Look for any tags and linkify them */ $str_tags = ''; $inform = ''; $tags = get_tags($body); /** * add a statusnet style reply tag if the original post was from there * and we are replying, and there isn't one already */ if ($parent_contact && $parent_contact['network'] === NETWORK_OSTATUS && $parent_contact['nick'] && !in_array('@' . $parent_contact['nick'], $tags)) { $body = '@' . $parent_contact['nick'] . ' ' . $body; $tags[] = '@' . $parent_contact['nick']; } $tagged = array(); $private_forum = false; if (count($tags)) { foreach ($tags as $tag) { // If we already tagged 'Robert Johnson', don't try and tag 'Robert'. // Robert Johnson should be first in the $tags array $fullnametagged = false; for ($x = 0; $x < count($tagged); $x++) { if (stristr($tagged[$x], $tag . ' ')) { $fullnametagged = true; break; } } if ($fullnametagged) { continue; } $success = handle_tag($a, $body, $inform, $str_tags, local_user() ? local_user() : $profile_uid, $tag, $network); if ($success['replaced']) { $tagged[] = $tag; } if (is_array($success['contact']) && intval($success['contact']['prv'])) { $private_forum = true; $private_id = $success['contact']['id']; } } } if ($private_forum && !$parent && !$private) { // we tagged a private forum in a top level post and the message was public. // Restrict it. $private = 1; $str_contact_allow = '<' . $private_id . '>'; } $attachments = ''; $match = false; if (preg_match_all('/(\\[attachment\\]([0-9]+)\\[\\/attachment\\])/', $body, $match)) { foreach ($match[2] as $mtch) { $r = q("SELECT `id`,`filename`,`filesize`,`filetype` FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($profile_uid), intval($mtch)); if (count($r)) { if (strlen($attachments)) { $attachments .= ','; } $attachments .= '[attach]href="' . $a->get_baseurl() . '/attach/' . $r[0]['id'] . '" length="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . ($r[0]['filename'] ? $r[0]['filename'] : '') . '"[/attach]'; } $body = str_replace($match[1], '', $body); } } $wall = 0; if ($post_type === 'wall' || $post_type === 'wall-comment') { $wall = 1; } if (!strlen($verb)) { $verb = ACTIVITY_POST; } if ($network == "") { $network = NETWORK_DFRN; } $gravity = $parent ? 6 : 0; // even if the post arrived via API we are considering that it // originated on this site by default for determining relayability. $origin = x($_REQUEST, 'origin') ? intval($_REQUEST['origin']) : 1; $notify_type = $parent ? 'comment-new' : 'wall-new'; $uri = $message_id ? $message_id : item_new_uri($a->get_hostname(), $profile_uid); // Fallback so that we alway have a thr-parent if (!$thr_parent) { $thr_parent = $uri; } $datarray = array(); $datarray['uid'] = $profile_uid; $datarray['type'] = $post_type; $datarray['wall'] = $wall; $datarray['gravity'] = $gravity; $datarray['network'] = $network; $datarray['contact-id'] = $contact_id; $datarray['owner-name'] = $contact_record['name']; $datarray['owner-link'] = $contact_record['url']; $datarray['owner-avatar'] = $contact_record['thumb']; $datarray['author-name'] = $author['name']; $datarray['author-link'] = $author['url']; $datarray['author-avatar'] = $author['thumb']; $datarray['created'] = datetime_convert(); $datarray['edited'] = datetime_convert(); $datarray['commented'] = datetime_convert(); $datarray['received'] = datetime_convert(); $datarray['changed'] = datetime_convert(); $datarray['guid'] = $guid; $datarray['uri'] = $uri; $datarray['title'] = $title; $datarray['body'] = $body; $datarray['app'] = $app; $datarray['location'] = $location; $datarray['coord'] = $coord; $datarray['tag'] = $str_tags; $datarray['file'] = $categories; $datarray['inform'] = $inform; $datarray['verb'] = $verb; $datarray['object-type'] = $objecttype; $datarray['allow_cid'] = $str_contact_allow; $datarray['allow_gid'] = $str_group_allow; $datarray['deny_cid'] = $str_contact_deny; $datarray['deny_gid'] = $str_group_deny; $datarray['private'] = $private; $datarray['pubmail'] = $pubmail_enable; $datarray['attach'] = $attachments; $datarray['bookmark'] = intval($bookmark); $datarray['thr-parent'] = $thr_parent; $datarray['postopts'] = $postopts; $datarray['origin'] = $origin; $datarray['moderated'] = $allow_moderated; /** * These fields are for the convenience of plugins... * 'self' if true indicates the owner is posting on their own wall * If parent is 0 it is a top-level post. */ $datarray['parent'] = $parent; $datarray['self'] = $self; // $datarray['prvnets'] = $user['prvnets']; if ($orig_post) { $datarray['edit'] = true; } // preview mode - prepare the body for display and send it via json if ($preview) { require_once 'include/conversation.php'; $o = conversation($a, array(array_merge($contact_record, $datarray)), 'search', false, true); logger('preview: ' . $o); echo json_encode(array('preview' => $o)); killme(); } call_hooks('post_local', $datarray); if (x($datarray, 'cancel')) { logger('mod_item: post cancelled by plugin.'); if ($return_path) { goaway($a->get_baseurl() . "/" . $return_path); } $json = array('cancel' => 1); if (x($_REQUEST, 'jsreload') && strlen($_REQUEST['jsreload'])) { $json['reload'] = $a->get_baseurl() . '/' . $_REQUEST['jsreload']; } echo json_encode($json); killme(); } if ($orig_post) { $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `attach` = '%s', `file` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($datarray['title']), dbesc($datarray['body']), dbesc($datarray['tag']), dbesc($datarray['attach']), dbesc($datarray['file']), dbesc(datetime_convert()), dbesc(datetime_convert()), intval($post_id), intval($profile_uid)); create_tags_from_item($post_id); create_files_from_item($post_id); update_thread($post_id); // update filetags in pconfig file_tag_update_pconfig($uid, $categories_old, $categories_new, 'category'); proc_run('php', "include/notifier.php", 'edit_post', "{$post_id}"); if (x($_REQUEST, 'return') && strlen($return_path)) { logger('return: ' . $return_path); goaway($a->get_baseurl() . "/" . $return_path); } killme(); } else { $post_id = 0; } $r = q("INSERT INTO `item` (`guid`, `uid`,`type`,`wall`,`gravity`, `network`, `contact-id`,`owner-name`,`owner-link`,`owner-avatar`, \n\t\t`author-name`, `author-link`, `author-avatar`, `created`, `edited`, `commented`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`, \n\t\t`tag`, `inform`, `verb`, `object-type`, `postopts`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark`,`origin`, `moderated`, `file` )\n\t\tVALUES( '%s', %d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s' )", dbesc($datarray['guid']), intval($datarray['uid']), dbesc($datarray['type']), intval($datarray['wall']), intval($datarray['gravity']), dbesc($datarray['network']), intval($datarray['contact-id']), dbesc($datarray['owner-name']), dbesc($datarray['owner-link']), dbesc($datarray['owner-avatar']), dbesc($datarray['author-name']), dbesc($datarray['author-link']), dbesc($datarray['author-avatar']), dbesc($datarray['created']), dbesc($datarray['edited']), dbesc($datarray['commented']), dbesc($datarray['received']), dbesc($datarray['changed']), dbesc($datarray['uri']), dbesc($datarray['thr-parent']), dbesc($datarray['title']), dbesc($datarray['body']), dbesc($datarray['app']), dbesc($datarray['location']), dbesc($datarray['coord']), dbesc($datarray['tag']), dbesc($datarray['inform']), dbesc($datarray['verb']), dbesc($datarray['object-type']), dbesc($datarray['postopts']), dbesc($datarray['allow_cid']), dbesc($datarray['allow_gid']), dbesc($datarray['deny_cid']), dbesc($datarray['deny_gid']), intval($datarray['private']), intval($datarray['pubmail']), dbesc($datarray['attach']), intval($datarray['bookmark']), intval($datarray['origin']), intval($datarray['moderated']), dbesc($datarray['file'])); $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($datarray['uri'])); if (count($r)) { $post_id = $r[0]['id']; logger('mod_item: saved item ' . $post_id); add_thread($post_id); // update filetags in pconfig file_tag_update_pconfig($uid, $categories_old, $categories_new, 'category'); // Store the fresh generated item into the cache $cachefile = get_cachefile($datarray["guid"] . "-" . hash("md5", $datarray['body'])); if ($cachefile != '' and !file_exists($cachefile)) { $s = prepare_text($datarray['body']); $stamp1 = microtime(true); file_put_contents($cachefile, $s); $a->save_timestamp($stamp1, "file"); logger('mod_item: put item ' . $r[0]['id'] . ' into cachefile ' . $cachefile); } if ($parent) { // This item is the last leaf and gets the comment box, clear any ancestors $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d ", dbesc(datetime_convert()), intval($parent)); update_thread($parent, true); // Inherit ACLs from the parent item. $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d\n\t\t\t\tWHERE `id` = %d", dbesc($parent_item['allow_cid']), dbesc($parent_item['allow_gid']), dbesc($parent_item['deny_cid']), dbesc($parent_item['deny_gid']), intval($parent_item['private']), intval($post_id)); if ($contact_record != $author) { notification(array('type' => NOTIFY_COMMENT, 'notify_flags' => $user['notify-flags'], 'language' => $user['language'], 'to_name' => $user['username'], 'to_email' => $user['email'], 'uid' => $user['uid'], 'item' => $datarray, 'link' => $a->get_baseurl() . '/display/' . urlencode($datarray['guid']), 'source_name' => $datarray['author-name'], 'source_link' => $datarray['author-link'], 'source_photo' => $datarray['author-avatar'], 'verb' => ACTIVITY_POST, 'otype' => 'item', 'parent' => $parent, 'parent_uri' => $parent_item['uri'])); } // Store the comment signature information in case we need to relay to Diaspora store_diaspora_comment_sig($datarray, $author, $self ? $a->user['prvkey'] : false, $parent_item, $post_id); } else { $parent = $post_id; if ($contact_record != $author) { notification(array('type' => NOTIFY_WALL, 'notify_flags' => $user['notify-flags'], 'language' => $user['language'], 'to_name' => $user['username'], 'to_email' => $user['email'], 'uid' => $user['uid'], 'item' => $datarray, 'link' => $a->get_baseurl() . '/display/' . urlencode($datarray['guid']), 'source_name' => $datarray['author-name'], 'source_link' => $datarray['author-link'], 'source_photo' => $datarray['author-avatar'], 'verb' => ACTIVITY_POST, 'otype' => 'item')); } } // fallback so that parent always gets set to non-zero. if (!$parent) { $parent = $post_id; } $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `plink` = '%s', `changed` = '%s', `last-child` = 1, `visible` = 1\n\t\t\tWHERE `id` = %d", intval($parent), dbesc($parent == $post_id ? $uri : $parent_item['uri']), dbesc($a->get_baseurl() . '/display/' . urlencode($datarray['guid'])), dbesc(datetime_convert()), intval($post_id)); // photo comments turn the corresponding item visible to the profile wall // This way we don't see every picture in your new photo album posted to your wall at once. // They will show up as people comment on them. if (!$parent_item['visible']) { $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d", intval($parent_item['id'])); update_thread($parent_item['id']); } } else { logger('mod_item: unable to retrieve post that was just stored.'); notice(t('System error. Post not saved.') . EOL); goaway($a->get_baseurl() . "/" . $return_path); // NOTREACHED } // update the commented timestamp on the parent q("UPDATE `item` set `commented` = '%s', `changed` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), dbesc(datetime_convert()), intval($parent)); update_thread($parent); $datarray['id'] = $post_id; $datarray['plink'] = $a->get_baseurl() . '/display/' . urlencode($datarray['guid']); call_hooks('post_local_end', $datarray); if (strlen($emailcc) && $profile_uid == local_user()) { $erecips = explode(',', $emailcc); if (count($erecips)) { foreach ($erecips as $recip) { $addr = trim($recip); if (!strlen($addr)) { continue; } $disclaimer = '<hr />' . sprintf(t('This message was sent to you by %s, a member of the Friendica social network.'), $a->user['username']) . '<br />'; $disclaimer .= sprintf(t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL; $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL; if (!$datarray['title'] == '') { $subject = email_header_encode($datarray['title'], 'UTF-8'); } else { $subject = email_header_encode('[Friendica]' . ' ' . sprintf(t('%s posted an update.'), $a->user['username']), 'UTF-8'); } $link = '<a href="' . $a->get_baseurl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />'; $html = prepare_body($datarray); $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>'; include_once 'include/html2plain.php'; $params = array('fromName' => $a->user['username'], 'fromEmail' => $a->user['email'], 'toEmail' => $addr, 'replyTo' => $a->user['email'], 'messageSubject' => $subject, 'htmlVersion' => $message, 'textVersion' => html2plain($html . $disclaimer)); enotify::send($params); } } } create_tags_from_item($post_id); create_files_from_item($post_id); update_thread($post_id); // This is a real juggling act on shared hosting services which kill your processes // e.g. dreamhost. We used to start delivery to our native delivery agents in the background // and then run our plugin delivery from the foreground. We're now doing plugin delivery first, // because as soon as you start loading up a bunch of remote delivey processes, *this* page is // likely to get killed off. If you end up looking at an /item URL and a blank page, // it's very likely the delivery got killed before all your friends could be notified. // Currently the only realistic fixes are to use a reliable server - which precludes shared hosting, // or cut back on plugins which do remote deliveries. proc_run('php', "include/notifier.php", $notify_type, "{$post_id}"); logger('post_complete'); item_post_return($a->get_baseurl(), $api_source, $return_path); // NOTREACHED }